Beispiel #1
0
        //called within CheckEmailSend, sends email with the appropriate data
        private void sendEmailUpdate(double curTime, int events)
        {
            //send Counter, timeElapsed, video?

            try
            {
                emailCounter++;
                System.Net.NetworkCredential cred    = new System.Net.NetworkCredential(sender, password);
                System.Net.Mail.MailMessage  message = new System.Net.Mail.MailMessage();
                message.To.Add(recipient); //can add multiple recipients by duplicating message.To.Add(recipient) line
                message.From    = new System.Net.Mail.MailAddress(sender);
                message.Subject = "Update" + DateTime.Today.Date + emailCounter.ToString();
                message.Body    = "Number of Events Completed: " + events.ToString() + "\n" +
                                  "Time Elapsed: " + curTime.ToString() + "\n";

                //can attach data to the email (such as the movement value file demonstrated below)
                System.Net.Mail.Attachment data = null;
                if (sendData)
                {
                    data = new System.Net.Mail.Attachment(fileHandler.getMovementFileName());
                    message.Attachments.Add(data);
                }

                //Change the client if not using gmail
                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com");
                client.Credentials    = cred;
                client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                client.EnableSsl      = true;
                client.Port           = 587;

                //send the email
                client.Send(message);
                if (sendData && data != null)
                {
                    data.Dispose();
                }
            }
            catch
            {
                Console.WriteLine("unable to send email from " + sender);
                if (sender == "")
                {
                    Console.WriteLine("no sender provided for email");
                }
            }
        }