using System; using System.Collections.Generic; using System.Text; using MindTouch.Dream; using System.IO; namespace VespaLabsEmail { class Program { static void Main(string[] args) { // flags bool Email_Alerts = false; bool Daily_My_Watchlist_Alert = false; bool Daily_Contributions_Page_Alert = false; bool Monthly_VespaLabs_Update = false; // get email client ready System.Net.Mail.SmtpClient smtpclient = new System.Net.Mail.SmtpClient(); *** smtpclient.Host = "your email host"; //smtpclient.Port = smtpport; // get admin plug *** warning we are using admin priviledges for retrieving information and emailing to users*** *** Plug adminPlug = Plug.New("http://www.vespalabs.org/@api/deki"); *** adminPlug.At("users", "authenticate").WithCredentials("admin", "password").GetAsync().Wait(); // get users Console.WriteLine("Get Users"); DreamMessage usersResult = adminPlug.At("users").GetAsync().Wait(); Console.WriteLine("Got Users"); XDoc xmlResult = usersResult.AsDocument(); XDoc users = xmlResult["//users"]; // Use the following link to help you get stuck into the data // http://wiki.developer.mindtouch.com/MindTouch_Dream/Tutorials/Using_the_XDoc_class_to_create_and_manipulate_XML_documents xmlResult.Save("user.xml"); // for debugging foreach (XDoc user in users[".//user"]) { //reset flags Email_Alerts = false; Daily_My_Watchlist_Alert = false; Daily_Contributions_Page_Alert = false; Monthly_VespaLabs_Update = false; Console.Write(user["username"].Contents + " : "); Console.WriteLine(user["email"].Contents); // find what email options the user has set through watched pages DreamMessage favoritesResult = adminPlug.At("users", "=" + user["username"].Contents, "favorites").GetAsync().Wait(); xmlResult = favoritesResult.AsDocument(); // check the "magic" pages that users use to manage alerts foreach (XDoc pageTitle in xmlResult[".//title"]) { if (pageTitle.Contents.Equals("Email Alerts")) Email_Alerts = true; // emails enabled, below are "which" emails if (pageTitle.Contents.Equals("Daily My Watchlist Alert")) Daily_My_Watchlist_Alert = true; if (pageTitle.Contents.Equals("Daily Contributions Page Alert")) Daily_Contributions_Page_Alert = true; if (pageTitle.Contents.Equals("Monthly vespalabs Update")) Monthly_VespaLabs_Update = true; } if (Email_Alerts && !user["email"].Contents.Equals("")) { //format and send emails System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); msg.To.Add(user["email"].Contents); *** msg.From = new System.Net.Mail.MailAddress("vespalabs@internetscooter.com", "vespalabs.org"); msg.IsBodyHtml = true; string subjectTag = "vespalabs: "; string starthtml = ""; string endhtml = ""; string greetings = "

Hi " + user["fullname"].Contents + ",

"; string instructions = "

This is an automated email to keep you up to date on what is happening at vespalabs.org." + "To manage your alerts please login and visit Email Alerts.

"; // add content based on options msg.Body = starthtml + greetings + instructions; // Monthly if (Monthly_VespaLabs_Update && DateTime.Now.Day.Equals(1)) { Console.WriteLine(" Send: Monthly vespalabs Update"); subjectTag += " :Monthly Update: "; msg.Body += "

Monthly Update

"; msg.Body += "

test content

"; } // Daily if (Daily_My_Watchlist_Alert) { Console.WriteLine(" Send: Watchlist AND Contributions Alert"); subjectTag += " :Watchlist: "; msg.Body += "

Watched Pages

"; msg.Body += "

test content

"; } if (Daily_Contributions_Page_Alert) { Console.WriteLine(" Send: Watchlist Alert"); subjectTag += " :Contributions: "; msg.Body += "

Changes to My Contributions

"; msg.Body += "

test content

"; //DreamMessage pagesResult = adminPlug.At("users", "=" + user["username"].Contents, "favorites", "feed").GetAsync().Wait(); //// Console.WriteLine("Email Enabled"); //xmlResult = pagesResult.AsDocument(); //xmlResult.Save("feed" + user["username"].Contents + ".xml"); } msg.Subject = subjectTag; msg.Body += endhtml; smtpclient.Send(msg); } } Console.WriteLine("Done"); Console.ReadKey();// wait for user to kill process with keypress