public ActionResult Index(MyMailModel objModelMail, string submit) { if (submit == "Productscar") { string from1 = "mandla.anilbabu@gmail.com"; string email1 = objModelMail.Email; using (MailMessage mail = new MailMessage("mandla.anilbabu@gmail.com",from1)) { mail.Subject = "This is subject new cars theam"; mail.Body = "New cars Theam 1 selected" + Environment.NewLine + "FROM :" + email1; mail.IsBodyHtml = false; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential networkCredential = new NetworkCredential(from1, "PWD"); smtp.UseDefaultCredentials = true; smtp.Credentials = networkCredential; smtp.Port = 587; smtp.Send(mail); ViewBag.Message = "Sent"; ViewData["Message"] = "Saved theam successfully,this will update soon..."; return View("Index", objModelMail); } } }
public class MyMailModel { public string From { get; set; } [Required(ErrorMessage = "Please enter your email address")] [RegularExpression(@"[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}", ErrorMessage = "Please enter correct email")] public string Email { get; set; } public string To { get; set; } public string Subject { get; set; } public string Body { get; set; } }
System.Net.Mail.MailMessage.To
foreach (var address in addresses.Split(new [] {";"}, StringSplitOptions.RemoveEmptyEntries)) { mailMessage.To.Add(address); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)