コード例 #1
0
        protected override void OnStart(string[] args)
        {
            EventLog.WriteEntry("Service Started");

            XmlDocument xml = new XmlDocument();

            xml.Load("C:/Users/David/Documents/Visual Studio 2012/Projects/TicketsGetEmail/TicketsGetEmail/Configuration.xml");//loads the Configuration.xml file

            XmlNode node = xml.SelectSingleNode("/Configuration");

            ConnString = node.ChildNodes[0].InnerText.ToString();//gets the connection string from the Configuration.xml file
            
            Email mail = new Email();

            DataSet ds = mail.GetPreferences(ConnString);

            DeleteMessage = ds.Tables[0].Rows[0]["DeleteMessages"].ToString();//gets whether to delete messages from the inbox

            IntervalLength = Convert.ToInt32(ds.Tables[0].Rows[0]["IntervalLength"]);//gets the interval length for the timer from the Configuration.xml file

            EmailAddress = ds.Tables[0].Rows[0]["EmailAddress"].ToString();//gets the Email Address of the inbox to retrieve emails from

            Password = ds.Tables[0].Rows[0]["Password"].ToString();//gets the password for the above Email Address

            HostName = ds.Tables[0].Rows[0]["PopHostName"].ToString();

            Port = Convert.ToInt32(ds.Tables[0].Rows[0]["PopPort"]);

            UseSsl = Convert.ToBoolean(ds.Tables[0].Rows[0]["PopUseSsl"]);

            SendReceivedEmail = Convert.ToBoolean(ds.Tables[0].Rows[0]["SendReceivedEmail"]);

            SendOverDueReceived = Convert.ToBoolean(ds.Tables[0].Rows[0]["SendOverDueReceivedEmail"]);

            mail.RetrieveEmails(EmailAddress, Password, ConnString, DeleteMessage, HostName, Port, UseSsl,SendReceivedEmail,SendOverDueReceived);//method that retrieves the emails and save them in the database

            System.Timers.Timer timer = new System.Timers.Timer(IntervalLength);//timer to run for the length of the IntervalLength variable

            timer.AutoReset = true;//automatically resets the timer after it elapses

            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);//runs the timer_Elapsed method after the timer elapses

            timer.Start();//starts the timer
        }
コード例 #2
0
        public void ReceivedEmail(string itemail,string password, string EmailAddress, string Body, string subject,string ConnString)
        {
            Email mail = new Email();

            DataSet ds = mail.GetPreferences(ConnString);

            string SMTPHost = ds.Tables[0].Rows[0]["SMTPHost"].ToString();

            int SMTPPort = Convert.ToInt32(ds.Tables[0].Rows[0]["SMTPPort"]);

            bool UseSsl = Convert.ToBoolean(ds.Tables[0].Rows[0]["SMTPUseSsl"]);

            MailMessage message = new MailMessage();

            message.From = new MailAddress("*****@*****.**");

            message.To.Add(new MailAddress(EmailAddress));

            message.Subject = subject;

            message.Body = Body;

            SmtpClient client = new SmtpClient();

            client.Host = SMTPHost;

            client.Port = SMTPPort;

            client.EnableSsl = UseSsl;

            client.Credentials = new System.Net.NetworkCredential(itemail, password);

            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            client.Send(message);
        }
コード例 #3
0
        public static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)//this is the timer_Elapsed method and runs everytime the timer elapses
        {
            Email mail = new Email();

            XmlDocument xml = new XmlDocument();

            xml.Load("C:/Users/David/Documents/Visual Studio 2012/Projects/TicketsGetEmail/TicketsGetEmail/Configuration.xml");//loads the Configuration.xml file

            XmlNode node = xml.SelectSingleNode("/Configuration");

            ConnString = node.ChildNodes[0].InnerText.ToString();//gets the connection string from the Configuration.xml file

            DataSet ds = mail.GetPreferences(ConnString);

            DeleteMessage = ds.Tables[0].Rows[0]["DeleteMessages"].ToString();//gets whether to delete messages from the inbox

            IntervalLength = Convert.ToInt32(ds.Tables[0].Rows[0]["IntervalLength"]);//gets the interval length for the timer from the Configuration.xml file

            EmailAddress = ds.Tables[0].Rows[0]["EmailAddress"].ToString();//gets the Email Address of the inbox to retrieve emails from

            Password = ds.Tables[0].Rows[0]["Password"].ToString();//gets the password for the above Email Address

            HostName = ds.Tables[0].Rows[0]["PopHostName"].ToString();

            Port = Convert.ToInt32(ds.Tables[0].Rows[0]["PopPort"]);

            UseSsl = Convert.ToBoolean(ds.Tables[0].Rows[0]["PopUseSsl"]);

            mail.RetrieveEmails(EmailAddress, Password, ConnString, DeleteMessage, HostName,Port,UseSsl,SendReceivedEmail,SendOverDueReceived);//calls the method that retrieves the emails and saves them in the database
        }