Пример #1
0
        /// <summary>
        /// Sends an email for the given details
        /// </summary>
        /// <param name="emailDetail">Email details</param>
        public void Send(EmailDetail emailDetail)
        {
            var mail = new MailMessage
            {
                Subject    = emailDetail.Subject,
                Body       = RelativeToAbsoluteUrls(emailDetail.Body),
                IsBodyHtml = emailDetail.IsBodyHtml
            };

            AddSender(mail, emailDetail);
            AddRecipients(mail, emailDetail);
            AddBlindCopyRecipients(mail, emailDetail);
            AddAttachments(mail, emailDetail);
            try
            {
                using (var client = new SmtpClient())
                {
                    client.Send(mail);
                }
            }
            catch (SmtpException ex)
            {
                _loggingService.Log(string.Format("Error sending mail with code: {0}, {1}", ex.StatusCode, ex.Message), LogLevel.Error);
            }
        }
        public ActionResult Register(RegistrationFormViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return CurrentUmbracoPage();
            }

            var member = Members.CreateRegistrationModel();
            member.Name = vm.Name;
            member.Email = vm.Email;
            member.Password = vm.Password;
            member.UsernameIsEmail = true;
            MembershipCreateStatus status;
            Members.RegisterMember(member, out status);
            if (!status.Equals(MembershipCreateStatus.Success))
            {
                return CurrentUmbracoPage();
            }

            var email = new EmailDetail
            {
                To = new List<string> { member.Email },
                Subject = "Registraion confirmation",
                IsBodyHtml = false
            };
            _mailer.Send(email);

            return RedirectToCurrentUmbracoPage();
        }
Пример #3
0
        private static void AddAttachments(MailMessage mail, EmailDetail emailDetail)
        {
            if (emailDetail.Attachments == null || !emailDetail.Attachments.Any())
            {
                return;
            }

            foreach (var file in emailDetail.Attachments.Where(x => !string.IsNullOrEmpty(x)))
            {
                mail.Attachments.Add(new Attachment(string.Concat(AppDomain.CurrentDomain.BaseDirectory, file)));
            }
        }
Пример #4
0
        private static void AddAttachments(MailMessage mail, EmailDetail emailDetail)
        {
            if (emailDetail.Attachments == null || !emailDetail.Attachments.Any())
            {
                return;
            }

            foreach (var file in emailDetail.Attachments.Where(x => !string.IsNullOrEmpty(x)))
            {
                mail.Attachments.Add(new Attachment(string.Concat(AppDomain.CurrentDomain.BaseDirectory, file)));
            }
        }
Пример #5
0
        private static void AddBlindCopyRecipients(MailMessage mail, EmailDetail emailDetail)
        {
            if (emailDetail.Bcc == null || !emailDetail.Bcc.Any())
            {
                return;
            }

            foreach (var to in emailDetail.Bcc.Distinct())
            {
                mail.Bcc.Add(new MailAddress(to));
            }
        }
Пример #6
0
        private static void AddRecipients(MailMessage mail, EmailDetail emailDetail)
        {
            if (emailDetail.To == null || !emailDetail.To.Any())
            {
                mail.To.Add(new MailAddress(_emailAddress));
                return;
            }

            foreach (var to in emailDetail.To.Distinct())
            {
                mail.To.Add(new MailAddress(to));
            }
        }
        public ActionResult AjaxSendEmail(ContactFormViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return PartialView("_ContactForm", vm);
            }

            var email = new EmailDetail
            {
                From = vm.Email,
                DisplayName = vm.FullName,
                Subject = vm.Subject,
                Body = vm.Message,
                IsBodyHtml = false
            };
            _mailer.Send(email);

            return Content(string.Format("<div class=\"alert alert-success\" role=\"alert\">{0}</div>", vm.ThankYouText), "text/html");
        }
Пример #8
0
 /// <summary>
 /// Sends an email for the given details
 /// </summary>
 /// <param name="emailDetail">Email details</param>
 public void Send(EmailDetail emailDetail)
 {
     var mail = new MailMessage
     {
         Subject = emailDetail.Subject,
         Body = RelativeToAbsoluteUrls(emailDetail.Body),
         IsBodyHtml = emailDetail.IsBodyHtml
     };
     AddSender(mail, emailDetail);
     AddRecipients(mail, emailDetail);
     AddBlindCopyRecipients(mail, emailDetail);
     AddAttachments(mail, emailDetail);
     try
     {
         using (var client = new SmtpClient())
         {
             client.Send(mail);
         }
     }
     catch (SmtpException ex)
     {
         _loggingService.Log(string.Format("Error sending mail with code: {0}, {1}", ex.StatusCode, ex.Message), LogLevel.Error);
     }
 }
Пример #9
0
        private static void AddBlindCopyRecipients(MailMessage mail, EmailDetail emailDetail)
        {
            if (emailDetail.Bcc == null || !emailDetail.Bcc.Any())
            {
                return;
            }

            foreach (var to in emailDetail.Bcc.Distinct())
            {
                mail.Bcc.Add(new MailAddress(to));
            }
        }
Пример #10
0
 private static void AddSender(MailMessage mail, EmailDetail emailDetail)
 {
     mail.From = string.IsNullOrEmpty(emailDetail.From)
         ? new MailAddress(_emailAddress, _displayName)
         : new MailAddress(emailDetail.From, emailDetail.DisplayName);
 }
Пример #11
0
        private static void AddRecipients(MailMessage mail, EmailDetail emailDetail)
        {
            if (emailDetail.To == null || !emailDetail.To.Any())
            {
                mail.To.Add(new MailAddress(_emailAddress));
                return;
            }

            foreach (var to in emailDetail.To.Distinct())
            {
                mail.To.Add(new MailAddress(to));
            }
        }
Пример #12
0
 private static void AddSender(MailMessage mail, EmailDetail emailDetail)
 {
     mail.From = string.IsNullOrEmpty(emailDetail.From)
         ? new MailAddress(_emailAddress, _displayName)
         : new MailAddress(emailDetail.From, emailDetail.DisplayName);
 }