private string GetMailBody(ContactForm model) { var doc = new HtmlDocument(); doc.Load(Server.MapPath("~/Email/ContactForm.html")); var builder = new StringBuilder(doc.DocumentNode.SelectSingleNode("//body").WriteTo()); ReplacePlaceholder(builder, "NameSurnameTitle", Localization.ContactFormNameSurname); ReplacePlaceholder(builder, "NameSurname", model.NameSurname); ReplacePlaceholder(builder, "ClientEmailTitle", Localization.ContactFormClientEmail); ReplacePlaceholder(builder, "ClientEmail", model.ClientEmail); ReplacePlaceholder(builder, "DescriptionTitle", Localization.ContactFormDescription); ReplacePlaceholder(builder, "Description", model.Description); return builder.ToString(); }
public JsonResult Send(ContactForm model) { var success = true; try { if (!ModelState.IsValid) { success = false; } var body = GetMailBody(model); Utils.SendEmail(model.EmailFrom, model.EmailTo, Localization.ContactFormEmailSubject, body); } catch (Exception e) { LogHelper.Error(GetType(), e.ToString(), e); success = false; } return Json(new { success }); }