public ActionResult Contact(Contact model) { DataProvider.SendContact(model); ViewData["ContactSent"] = true; return View(); }
public static void SendContact(Contact contact) { var fromAddress = ConfigurationManager.AppSettings["EmailFrom"]; var toAddress = ConfigurationManager.AppSettings["EmailTo"]; string fromPassword = ConfigurationManager.AppSettings["EmailFromPassword"]; string subject = contact.Subject; string body = "מאת: " + contact.Name + "\n"; body += "אימייל: " + contact.Email + "\n"; body += "טלפון: " + contact.Phone + "\n"; body += "טלפון נייד: " + contact.Mobile + "\n"; body += "שם העסק: " + contact.BusinessName + "\n"; body += "ת.ז / ע.מ / ח.פ: " + contact.Id + "\n"; body += "כתובת העסק: " + contact.BusinessAddress + "\n"; body += "נושא: " + contact.Subject + "\n"; body += "הודעה: \n" + contact.Content + "\n"; body = HttpUtility.HtmlEncode(body); var smtp = new System.Net.Mail.SmtpClient(); { smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; smtp.Credentials = new NetworkCredential(fromAddress, fromPassword); smtp.Timeout = 20000; } smtp.Send(fromAddress, toAddress, subject, body); }