public void Send(EmailTemplate template) { try { string templatePath = VirtualPathUtility.ToAbsolute(String.Format("~/files/themes/{0}/templates/{1}", GraffitiContext.Current.Theme, template.TemplateName)); templatePath = HttpContext.Current.Server.MapPath(templatePath); string body = TemplateEngine.Evaluate(Util.GetFileText(templatePath), template.Context); using (MailMessage message = new MailMessage(_settings.EmailFrom, template.To)) { message.Subject = template.Subject; message.IsBodyHtml = template.IsHTML; message.Body = body; SendMailMessage(message); } } catch (Exception ex) { Logger.Error(Create.New.LogMessage().WithTitle("Could not send e-mail"), ex); throw; } }
public static bool Send(EmailTemplate template) { Events.Instance().ExecuteBeforeEmailSent(template); string fileText = Util.GetFileText(HttpContext.Current.Server.MapPath("~/__utility/emails/" + template.TemplateName)); fileText = TemplateEngine.Evaluate(fileText, template.Context); using (MailMessage mm = new MailMessage(template.From ?? SiteSettings.Get().EmailFrom, template.To)) { mm.Subject = template.Subject; mm.IsBodyHtml = template.IsHTML; mm.Body = fileText; mm.Headers.Add("Reply-To", template.ReplyTo ?? template.From ?? SiteSettings.Get().EmailFrom); SendMailMessage(mm); } Events.Instance().ExecuteAfterEmailSent(template); return true; }
internal void ExecuteBeforeEmailSent(EmailTemplate template) { EmailTemplateHandler handler = Events[EmailBeforeSendOject] as EmailTemplateHandler; if (handler != null) handler(template, EventArgs.Empty); }
internal void ExecuteAfterEmailSent(EmailTemplate template) { EmailTemplateHandler handler = Events[EmailAfterSentObject] as EmailTemplateHandler; if (handler != null) handler(template, EventArgs.Empty); }
protected override void AfterCommit() { base.AfterCommit(); Post.UpdateCommentCount(PostId); if (!DontSendEmail) { try { EmailTemplateToolboxContext etc = new EmailTemplateToolboxContext(); etc.Put("comment", this); EmailTemplate ef = new EmailTemplate(); ef.Context = etc; ef.Subject = "New Comment: " + Post.Title; ef.To = Post.User.Email; ef.TemplateName = "comment.view"; ef.ReplyTo = this.Email; Emailer.Send(ef); Log.Info("Comment Sent", "Email sent to {0} ({1}) from the post \"{2}\" ({3}).", Post.User.ProperName, Post.User.Email, Post.Title, Post.Id); } catch (Exception ex) { Log.Error("Email Failure", ex.Message); } } ZCache.RemoveCache("Comments-" + PostId); ZCache.RemoveByPattern("Comments-Recent"); }
public static void SendPReqiresApprovalMessage(Post p, IGraffitiUser user) { List<IGraffitiUser> users = new List<IGraffitiUser>(); foreach(IGraffitiUser u in GraffitiUsers.GetUsers("*")) { if (GraffitiUsers.IsAdmin(u) || RolePermissionManager.GetPermissions(p.CategoryId, u).Publish) users.Add(u); } Macros m = new Macros(); EmailTemplateToolboxContext pttc = new EmailTemplateToolboxContext(); pttc.Put("sitesettings", SiteSettings.Get()); pttc.Put("post", p); pttc.Put("user", user); pttc.Put("macros", m); pttc.Put("home", m.FullUrl(new Urls().Home)); pttc.Put("adminUrl", m.FullUrl(VirtualPathUtility.ToAbsolute("~/graffiti-admin/posts/write/")) + "?id=" + p.Id + "&v=" + p.Version); string adminApprovalUrl = m.FullUrl(VirtualPathUtility.ToAbsolute("~/api/approve.ashx")) + "?key={0}&u={1}&id={2}&v={3}"; EmailTemplate template = new EmailTemplate(); template.Context = pttc; template.Subject = "You have content to approve: " + p.Title; template.TemplateName = "QueuedPost.view"; foreach (IGraffitiUser admin in users) { template.Context.Put("adminApprovalUrl", string.Format(adminApprovalUrl, admin.UniqueId, admin.Name, p.Id, p.Version)); try { template.To = admin.Email; Emailer.Send(template); //Emailer.Send("QueuedPost.view", admin.Email, "You have content to approve: " + p.Title, pttc); } catch(Exception ex) { Log.Error("Email Error", ex.Message); } } Log.Info("Post approval email", "{0} user(s) were sent an email to approve the post \"{1}\" (id: {2}).", users.Count,p.Title,p.Id); }
public static void SendRequestedChangesMessage(Post p, IGraffitiUser user) { List<IGraffitiUser> users = new List<IGraffitiUser>(); foreach (IGraffitiUser u in GraffitiUsers.GetUsers("*")) { if (GraffitiUsers.IsAdmin(u) || RolePermissionManager.GetPermissions(p.CategoryId, u).Publish) users.Add(u); } Macros m = new Macros(); EmailTemplateToolboxContext pttc = new EmailTemplateToolboxContext(); pttc.Put("sitesettings", SiteSettings.Get()); pttc.Put("post", p); pttc.Put("user", user); pttc.Put("macros", m); pttc.Put("home", m.FullUrl(new Urls().Home)); pttc.Put("adminUrl", m.FullUrl(VirtualPathUtility.ToAbsolute("~/graffiti-admin/posts/write/")) + "?id=" + p.Id + "&v=" + p.Version); EmailTemplate template = new EmailTemplate(); template.Context = pttc; template.To = p.User.Email; template.Subject = "Changes Requested: " + p.Title; template.TemplateName = "RequestChanges.view"; try { Emailer.Send(template); //Emailer.Send("RequestChanges.view", p.User.Email, "Changes Requested: " + p.Title, pttc); Log.Info("Post Changes Email", p.User.Email + " was sent an email requesting changes"); } catch (Exception ex) { Log.Error("Email Requested Changes Error", ex.Message); } }
public void ProcessRequest(HttpContext context) { if (context.Request.RequestType != "POST") return; if (context.Items["UserId"] == null) return; context.Response.ContentType = "text/plain"; switch (context.Request.QueryString["command"]) { case "newComment": Comment comment = new Comment(); comment.Name = context.Request.Form["author"]; comment.WebSite = context.Request.Form["url"]; comment.Email = context.Request.Form["email"]; comment.Body = context.Request.Form["comment"]; if (!context.Request.IsAuthenticated && String.IsNullOrEmpty(comment.Name)) { context.Response.Write("Please enter your name"); return; } if (String.IsNullOrEmpty(comment.Body)) { context.Response.Write("Please enter a comment"); return; } comment.IPAddress = context.Request.UserHostAddress; comment.PostId = Int32.Parse(context.Request.Form["comment_post_ID"]); comment.Published = DateTime.Now.AddHours(SiteSettings.Get().TimeZoneOffSet); comment.Save(); context.Response.Write("Your comment has been received and will be published shortly. Thanks!"); break; case "newContactMessage": string subject = context.Request.Form["subject"]; string email = context.Request.Form["email"]; string name = context.Request.Form["name"]; string message = context.Request.Form["message"]; if (string.IsNullOrEmpty(subject) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(message)) { context.Response.Write("All of the fields are required, your message has not been sent"); context.Response.End(); return; } if (!Regex.IsMatch(email, @"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b", RegexOptions.IgnoreCase)) { context.Response.Write("The email address you entered is not valid"); context.Response.End(); return; } EmailTemplateToolboxContext templateContext = new EmailTemplateToolboxContext(); templateContext.Put("subject", context.Server.HtmlEncode(subject)); templateContext.Put("email", context.Server.HtmlEncode(email)); templateContext.Put("name", context.Server.HtmlEncode(name)); templateContext.Put("message", Util.ConvertTextToHTML(message)); templateContext.Put("ip", context.Request.UserHostAddress); EmailTemplate et = new EmailTemplate(); et.Subject = "Contact Request: " + subject; et.Context = templateContext; et.From = email; et.TemplateName = "contact.view"; Log.Info("Contact Received", "Subject: {0}\nFrom:{1} ({2})\nIP:{3}\n\n{4}", subject, name, email, context.Request.UserHostAddress, message); foreach (IGraffitiUser user in GraffitiUsers.GetUsers(GraffitiUsers.AdminRole)) { et.To = user.Email; Emailer.Send(et); } context.Response.Write("Your message was received. Thanks!"); break; } }
void SendEmail(EmailTemplate template) { if (template != null) { _emailSender.Send(template); } }