public ActionResult Contact(ContactViewModel model) { if (ModelState.IsValid) { try { var title = "Message for GuruIn.NET"; var subject = string.Format("Message from {0} for GuruIn.NET", model.Name); var template = EmailEngine.GetTemplate("contact-us-template"); var body = template.Replace("*|MC:TITLE|*", title) .Replace("*|MC:SUBJECT|*", subject) .Replace("*|MC:EMAILTOBROWSERLINK|*", "http://www.GuruIn.NET") .Replace("{0}", model.Name) .Replace("{1}", model.Email) .Replace("{2}", model.Message.Replace("\r\n", "<br/>").Replace("\n", "<br/>").Replace("\r", "<br/>")) .Replace("*|CURRENT_YEAR|*", DateTime.Now.Year.ToString()) .Replace("*|LIST:COMPANY|*", "GuruIn.NET"); var fromTo = ConfigManager.Get <string>("SmtpUserName"); var result = EmailEngine.SendEmail(fromTo, "GuruIn.NET", fromTo, subject, subject, body, cc: (model.CopyUser && !string.IsNullOrWhiteSpace(model.Email) ? model.Email : null)); if (result) { Session["USER_MESSAGE"] = "Your message has been successfully sent. Thank you."; Session["USER_MESSAGE_SEVERITY"] = "Success"; Session["USER_MESSAGE_TITLE"] = "Message Sent"; return(RedirectToAction("Index")); } } catch (Exception ex) { Session["USER_MESSAGE"] = "Sorry, there was an error sending the message. Please try again later."; Session["USER_MESSAGE_SEVERITY"] = "Error"; _log.Error("HomeController - Contact", ex); } } return(View(model)); }
private bool NotifyNewComment(Comment newComment, int postId) { try { var domain = Request.Url.OriginalString.Replace(Request.Url.PathAndQuery, string.Empty); var postLink = domain + "/Blog/Post/" + postId; var commentLink = domain + "/Blog/Post/" + postId + "#comment-" + newComment.Id; var deleteLink = domain + "/Blog/DeleteComment/" + newComment.Id + "/" + DeleteCommentCode + "?postId=" + postId; var title = "New Comment on GuruIn.NET Blog"; var subject = "Review a new comment on GuruIn.NET Blog"; var template = EmailEngine.GetTemplate("new-comment-template"); var body = template.Replace("*|MC:TITLE|*", title) .Replace("*|MC:SUBJECT|*", subject) .Replace("*|MC:EMAILTOBROWSERLINK|*", "http://www.GuruIn.NET") .Replace("{0}", newComment.Name) .Replace("{1}", newComment.Email) .Replace("{2}", newComment.Content.Replace("\r\n", "<br/>").Replace("\n", "<br/>").Replace("\r", "<br/>")) .Replace("{3}", postLink) .Replace("{4}", commentLink) .Replace("{5}", deleteLink) .Replace("*|CURRENT_YEAR|*", DateTime.Now.Year.ToString()) .Replace("*|LIST:COMPANY|*", "GuruIn.NET"); var fromTo = ConfigManager.Get <string>("SmtpUserName"); var result = EmailEngine.SendEmail(fromTo, "GuruIn.NET", fromTo, subject, subject, body); return(result); } catch (Exception ex) { _log.Error("BlogsController - NotifyNewComment", ex); return(false); } }