Ejemplo n.º 1
0
        public bool SendTestEmail()
        {
            var emailMessage = new MailMessage();

            emailMessage.From = new MailAddress(GetFromEmail());
            emailMessage.To.Add(dasBlogSettings.SiteConfiguration.NotificationEMailAddress);
            emailMessage.To.Add(dasBlogSettings.SiteConfiguration.Contact);

            foreach (var user in dasBlogSettings.SecurityConfiguration.Users)
            {
                if (!string.IsNullOrWhiteSpace(user.EmailAddress))
                {
                    emailMessage.To.Add(user.EmailAddress);
                }
            }

            emailMessage.Subject = string.Format("SMTP email from {0}", dasBlogSettings.SiteConfiguration.Title);
            emailMessage.Body    = "Test ";

            var sendMailInfo = dasBlogSettings.GetMailInfo(emailMessage);

            try
            {
                sendMailInfo.SendMyMessage();
            }
            catch (Exception ex)
            {
                logger.LogInformation(new EventDataItem(EventCodes.SmtpError, new Uri(dasBlogSettings.SiteConfiguration.Root),
                                                        string.Format("SMTP Test Error: {0}", ex.Message)));

                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private SendMailInfo ComposeMail(string body)
        {
            var emailMessage = new MailMessage();

            if (!string.IsNullOrWhiteSpace(dasBlogSettings.SiteConfiguration.NotificationEMailAddress))
            {
                emailMessage.To.Add(dasBlogSettings.SiteConfiguration.NotificationEMailAddress);
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(dasBlogSettings.SiteConfiguration.Contact))
                {
                    emailMessage.To.Add(dasBlogSettings.SiteConfiguration.Contact);
                }
                else
                {
                    return(null);
                }
            }

            emailMessage.Subject = string.Format("Weblog Daily Activity Report for {0}, {1}", midnight.DayOfWeek, midnight.ToString("MMMM dd, yyyy"));

            emailMessage.Body = body;

            emailMessage.IsBodyHtml   = true;
            emailMessage.BodyEncoding = Encoding.UTF8;

            if (!string.IsNullOrWhiteSpace(dasBlogSettings.SiteConfiguration.SmtpUserName))
            {
                emailMessage.From = new MailAddress(dasBlogSettings.SiteConfiguration.SmtpUserName);
            }
            else
            {
                return(null);
            }

            return(dasBlogSettings.GetMailInfo(emailMessage));
        }