public ActionResult Contact(EnquiryModel model) { if (ModelState.IsValid) { string body = CreateEmailMessage(model); MailMessage mail = new MailMessage(); mail.To.Add(new MailAddress(WebSettings.AdminEmail)); mail.Subject = "Tradingwise Client enquiry from " + model.Name; mail.Body = body; mail.IsBodyHtml = true; try { using (SmtpClient client = new SmtpClient()) { client.Send(mail); } return RedirectToAction("Contact", new { status = true }); } catch (Exception) { return RedirectToAction("Contact", new { status = false }); } } return View(model); }
private string CreateEmailMessage(EnquiryModel model) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<b>CUSTOMER ENQUIRY</b><br />"); sb.AppendLine(string.Format("Customer Name : \t {0} <br />", model.Name)); sb.AppendLine(string.Format("Customer Telephone : \t {0} <br />", model.Telephone)); sb.AppendLine(string.Format("Customer Email : \t {0} <br />", model.Email)); sb.AppendLine(string.Format("Subject : \t {0} <br />", model.Subject)); sb.AppendLine(string.Format("Homepage : \t {0} <br />", model.HomePage)); sb.AppendLine(string.Format("Message : \t {0} <br />", model.Message)); return sb.ToString(); }