public static void NotifyNewComment(int commentId) { // Prepare Postal classes to work outside of ASP.NET request var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails")); var engines = new ViewEngineCollection(); engines.Add(new FileSystemRazorViewEngine(viewsPath)); var emailService = new EmailService(engines); // Get comment and send a notification. using (var db = new MailerDbContext()) { var comment = db.Comments.Find(commentId); var email = new NewCommentEmail { To = "*****@*****.**", UserName = comment.UserName, Comment = comment.Text }; emailService.Send(email); } }
public static void NotifyNewComment(int commentId) { var currentCultureName = Thread.CurrentThread.CurrentCulture.Name; if (currentCultureName != "es-ES") { throw new InvalidOperationException(String.Format("Current culture is {0}", currentCultureName)); } // Prepare Postal classes to work outside of ASP.NET request var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails")); var engines = new ViewEngineCollection(); engines.Add(new FileSystemRazorViewEngine(viewsPath)); var emailService = new EmailService(engines); // Get comment and send a notification. using (var db = new MailerDbContext()) { var comment = db.Comments.Find(commentId); var email = new NewCommentEmail { To = "*****@*****.**", UserName = comment.UserName, Comment = comment.Text }; emailService.Send(email); } }
public void NotifyNewComment(int commentId) { // Prepare Postal classes to work outside of ASP.NET request var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails")); var engines = new ViewEngineCollection(); engines.Add(new FileSystemRazorViewEngine(viewsPath)); var client = new SmtpClient() { Host = "smtp.sendgrid.net", Port = 587, EnableSsl = true, UseDefaultCredentials = false, Credentials = new NetworkCredential("xpto", "xtpo") }; var emailService = new EmailService(engines, () => client); // Get comment and send a notification. using (var db = new MailerDbContext()) { var comment = db.Comments.Find(commentId); //var evento = db.tbClientesEventos.Where(c => c.cdEvento.Equals("010701")); var email = new NewCommentEmail { To = "*****@*****.**", UserName = comment.UserName, Comment = comment.Text }; emailService.Send(email); } }
public ActionResult Create(Comment model) { if (ModelState.IsValid) { _db.Comments.Add(model); _db.SaveChanges(); var email = new NewCommentEmail { To = "*****@*****.**", UserName = model.UserName, Comment = model.Text }; email.Send(); } return(RedirectToAction("Index")); }
public static void Send(string emailAddress, string userName, string message) { var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails")); var engines = new ViewEngineCollection(); engines.Add(new FileSystemRazorViewEngine(viewsPath)); EmailService emailService = new EmailService(engines); // Get comment and send a notification. var email = new NewCommentEmail { To = emailAddress, UserName = userName, Comment = message }; emailService.Send(email); }