Пример #1
0
        public bool SendEmailMessage(EmailMessage message)
        {
            var success = false;
            try
            {
                var smtp = new SmtpClient
                {
                    Host = _config.Host,
                    Port = _config.Port,
                    EnableSsl = _config.Ssl,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(_config.Username, _config.Password)
                };

                using (var smtpMessage = new MailMessage(_config.Username, message.ToEmail))
                {
                    smtpMessage.Subject = message.Subject;
                    smtpMessage.Body = message.Body;
                    smtpMessage.IsBodyHtml = message.IsHtml;
                    smtp.Send(smtpMessage);
                }

                success = true;
            }
            catch (Exception ex)
            {
                //todo: add logging integration
                //throw;
            }

            return success;
        }
Пример #2
0
 public void send_email_via_gmail()
 {
     var email = new EmailMessage
     {
         IsHtml = false,
         Subject = "Gmail unit test email",
         ToEmail = "*****@*****.**",
         Body = String.Format("Gmail unit test body sent at {0:D}", DateTime.Now)
     };
     var success = _emailService.SendEmailMessage(email);
     Assert.IsTrue(success);
 }
Пример #3
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = model.UserName };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    var message = new EmailMessage();
                    message.ToEmail = model.EmailAddress;
                    message.Subject = "Insurance Website Registration";
                    message.IsHtml = false;
                    message.Body =
                        String.Format("You have succesfully registered for Vanderbuilt Insurance with the following" +
                                      "username: {0}", model.UserName);

                    var status = EmailService.SendEmailMessage(message);

                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Пример #4
0
 public bool SendEmailMessage(EmailMessage message)
 {
     return true;
 }