Beispiel #1
0
        private void SendEmail()
        {
            MailAddress from     = new MailAddress(config.EMAIL_SENDER);
            MailAddress to       = new MailAddress(DatabaseHelpers.GetResponderEmailAddress(model.Data.ResponderId, config));
            string      password = config.EMAIL_PASSWORD;
            string      subject  = TemplateReplace(config.EMAIL_ALERT_SUBJECT);
            string      template = File.ReadAllText(config.EMAIL_ALERT_TEMPLATE_PATH);
            string      body     = TemplateReplace(template);

            SmtpClient smtp = new SmtpClient
            {
                Host                  = config.EMAIL_SERVER,
                Port                  = Convert.ToInt32(config.EMAIL_PORT),
                EnableSsl             = Convert.ToBoolean(config.EMAIL_SSL),
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(from.Address, password)
            };

            using (MailMessage message = new MailMessage(from, to))
            {
                message.Subject    = subject;
                message.IsBodyHtml = true;
                message.Body       = body;

                if (model.Data.SeverityName.Equals("Critical"))
                {
                    message.Priority = MailPriority.High;
                }

                if (!String.IsNullOrEmpty(config.EMAIL_CC))
                {
                    foreach (string line in config.EMAIL_CC.Split(','))
                    {
                        message.CC.Add(new MailAddress(line));
                    }
                }
                smtp.Send(message);
            }
        }