public ActionResult EmailTest() { EmailViewModel ViewModel = new EmailViewModel { host = "smtp.gmail.com", port = 587, subject = "Testing Message from School Of Science Application", body = "This is a <i>testing messsage</i> from ASP.NET MVC 4" }; return View(ViewModel); }
public ActionResult EmailTest(EmailViewModel ViewModel) { if (ModelState.IsValid) { MailMessage mail = new MailMessage(); mail.To.Add(ViewModel.to); mail.From = new MailAddress(ViewModel.from); mail.Subject = ViewModel.subject; string Body = ViewModel.body; mail.Body = Body; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = ViewModel.host; smtp.Port = ViewModel.port; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential(ViewModel.username, ViewModel.password);// Enter seders User name and password smtp.EnableSsl = true; smtp.Send(mail); } return View(ViewModel); }