Пример #1
0
        private static void SendEmail(NotificationData notify, string body)
        {
            MailMessage mailMsg = new MailMessage();
            mailMsg.From = new MailAddress("*****@*****.**", "Kellogg's Keep Safe Module");
            // TEMPORARY USE ONLY!!!
            //mailMsg.Bcc.Add(new MailAddress("*****@*****.**", "Melissa Snow"));
            // TEMPORARY USE ONLY!!!

            mailMsg.Subject = "Kellogg's Keep Safe Module - Assignment received";
            //MailAddress mailTo = new MailAddress(address, name);
            //MailAddress mailTo = new MailAddress("*****@*****.**", "Melissa Snow");
            MailAddress mailTo = new MailAddress("*****@*****.**", "Dave Arbuckle");
            mailMsg.To.Add(mailTo);

            AlternateView htmlView = null;
            htmlView = AlternateView.CreateAlternateViewFromString(body);
            LinkedResource ksImage = new LinkedResource(Assembly.GetExecutingAssembly().GetManifestResourceStream("AssignmentNotificationEmail.Images.KeepSafe-logo-v6-sml.gif"));
            ksImage.ContentId = "keepsafe";
            htmlView.LinkedResources.Add(ksImage);
            ksImage = new LinkedResource(Assembly.GetExecutingAssembly().GetManifestResourceStream("AssignmentNotificationEmail.Images.University.png"));
            ksImage.ContentId = "training";
            htmlView.LinkedResources.Add(ksImage);

            htmlView.ContentType = new ContentType("text/html");
            mailMsg.AlternateViews.Add(htmlView);

            using (SmtpClient smtp = new SmtpClient("192.168.1.12"))
            {
                Console.WriteLine("Mail to " + mailMsg.To[0].Address);
                smtp.Send(mailMsg);
                LogTheSentEmail(notify.NotificationID);
                System.Threading.Thread.Sleep(250);
            }
        }
Пример #2
0
        private static void SendReviewEmail()
        {
            while (true)
            {
                DataTable dt = new DataTable();

                //SP:  NeedsNotificationEmail
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.Connection = conn;
                        cmd.CommandText = "[dbo].[NeedsNotificationEmail]";
                        cmd.CommandType = CommandType.StoredProcedure;
                        if (cmd.Connection.State != ConnectionState.Open)
                            cmd.Connection.Open();
                        dt.Load(cmd.ExecuteReader());
                        if (dt.Rows.Count == 0)
                        {
                            // no emails to send, we are done
                            return;
                        }
                    }
                }

                NotificationData notify = new NotificationData(dt.Rows[0]);

                StringBuilder recapBody = new StringBuilder();
                recapBody.AppendLine(BoilerplateTop(notify));
                recapBody.AppendLine(BoilerplateBottom());

                SendEmail(notify, recapBody.ToString());
            }
        }
Пример #3
0
        private static string BoilerplateTop(NotificationData notify)
        {

            StringBuilder sb = new StringBuilder();

            sb.Append("<body style='font-family: Arial, Helvetica, sans-serif;'>");

            sb.AppendLine("<div style='position: relative;display: inline-block;'>");
            sb.AppendLine("<img src='cid:training' />");
            sb.AppendLine("</div>");

            sb.AppendLine("<div>&nbsp;</div>");
            sb.AppendLine("<div>&nbsp;</div>");

            sb.Append("<span style='font-family:arial,helvetica,sans-serif;font-size: 14pt; font-weight: bold;'>");

            //sb.Append("  <span style='color:" + redColor + ";'>Reminder:&nbsp;</span>");
            sb.Append("You have been assigned \"");
            sb.Append(notify.QuizTopic);
            sb.Append("\" by ");
            sb.Append(notify.AssignedBy);
            sb.Append(".");
            sb.Append("</span>");
            sb.Append("<br />");
            sb.AppendLine("<br />");
            sb.Append("Due Date: ");
            sb.Append(notify.DueDate);
            sb.Append("<br />");
            sb.AppendLine("<br />");


            sb.AppendLine("<div style='font-size: 10pt;'>");
            sb.Append("Please click on the URL - ");
            sb.Append(string.Format("<a href=\"http://www1.saferemployees.com/Kellogg/ControlCenter/Home/Index?employeeid={0}\">http://www1.saferemployees.com/Kellogg/ControlCenter</a>", notify.EmployeeID));
            sb.AppendLine(" and click on the University notification to complete this assignment.");
            sb.Append("<p>The link above is unique to you so please do not forward on to another employee.</p>");
            sb.Append("</div>");
            sb.AppendLine("<div>&nbsp;</div>");
            return sb.ToString();
        }