Email Code

From $1

  • You do not have permissions to view this page - please try logging in.
Table of contents
No headers


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/..._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 = "<html><head></head><body>";
                    string endhtml = "</body></html>";
                    string greetings = "<h3><font face=\"Courier New\">Hi " + user["fullname"].Contents + ",</font></h3>";
                    string instructions = "<p><font face=\"Courier New\">This is an automated email to keep you up to date on what is happening at <A href=\"http://www.vespalabs.org\">vespalabs.org</a>." +
                        "To manage your alerts please login and visit <A href=\"http://www.vespalabs.org/1st_Read/Email_Alerts\">Email Alerts</a>.</font><p>";

                    // 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 += "<h3><font face=\"Courier New\">Monthly Update</font></h3>";
                        msg.Body += "<p>test content</p>";
                    }
                    // Daily
                    if (Daily_My_Watchlist_Alert)
                    {
                        Console.WriteLine(" Send: Watchlist AND Contributions Alert");
                        subjectTag += " :Watchlist: ";
                        msg.Body += "<h3><font face=\"Courier New\">Watched Pages</font></h3>";
                        msg.Body += "<p>test content</p>";
                    }
                    if (Daily_Contributions_Page_Alert)
                    {
                        Console.WriteLine(" Send: Watchlist Alert");
                        subjectTag += " :Contributions: ";
                        msg.Body += "<h3><font face=\"Courier New\">Changes to My Contributions</font></h3>";
                        msg.Body += "<p>test content</p>";
                        //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


Tags: (Edit tags)
  • No tags
FileSizeDateAttached by 
 email.cs
No description
6.02 kB22:09, 14 Aug 2008internetscooterActions
Comments (0)
You must login to post a comment.

 
Powered by MindTouch Core

Disclaimer: Vespa Labs contains information that is VERY likely to wreck your scooter and possibly yourself both intentionally (i.e. gaining more peformance while sacrificing reliability + safety) and unintentionally (i.e. misleading or incorrect information). Vespa Labs is only a wiki and intended as a dumping ground for information and not as a properly reviewed source. The same disclaimers that wikipedia.org use apply to Vespa Labs. The short version is use information at your own risk, both information on the main wiki and in the user areas are intended to be used only as "thought provoking" for someone that knows what they are doing. If you try to implement a "thought" Vespa Labs is not reponsible and if something goes wrong we hope that you live and update the offending information with corrections to warn others.

Vespa Labs is an international site and therefore may contain information that is not road legal in some countries/states and may also invalidate insurance policies. Treat all information as experimental and for "race use only" (i.e. not for road use - even if it is implied or explicitly stated). Refer to and adhere to your local road and legal rules, as well as the manufacturers recommendations.