SendCommentMail not working?

Feb 11, 2011 at 7:36 PM

I understand this is meant to send me an email each time someone comments on my posts? It never sends me an email... anyone know why?

Feb 12, 2011 at 6:31 AM

It works when i test it locally on visual studio, but it doesnt do anything when i test it live on the server.


What gives?

Feb 12, 2011 at 6:09 PM
Edited Feb 12, 2011 at 6:29 PM


Feb 13, 2011 at 5:28 PM


Feb 15, 2011 at 7:34 PM


Mar 7, 2011 at 8:35 PM

Bump, has someone figured this out?

Mar 8, 2011 at 11:01 PM

Check this thread out, see if it applies:


Mar 9, 2011 at 5:35 PM
msewell57 wrote:

Check this thread out, see if it applies:


Nah bro he had a different problem, my email works when i click test but it never sends a notification when someone leaves a comment.

Mar 13, 2011 at 12:02 PM


Mar 14, 2011 at 8:57 AM

There's several things in SendCommentMail that can prevent it from sending an email.

One thing is comment moderation.  Do you have the "Moderate comments" checkbox checked under Settings -> Comments?  And do you have any of the anti-spam extensions enabled?

If "moderate comments" is checked and the comment has been moderated by any of the anti-spam services or by any of the blacklist rules you have setup, then you won't get an email.  If "moderate comments" is unchecked and the comment is not approved, then you won't get an email.

After a comment is left and you are not sent an email, you might want to see how that comment is classified on the Comments tab in the control panel.  i.e. is the comment on the Pending tab, Approved tab or the Spam tab.  Generally, if it's on the Approved tab or Spam tab, you won't be sent an email since the comment has already been approved or marked as spam and doesn't need your attention.

Lastly, if you are logged into the blog and leave a comment on your own post, you won't get an email.

Mar 14, 2011 at 11:04 AM

So basically you only get an email if the comment needs admin action to confirm it? Can i make it so it sends an email when any comment is left (apart from spam)?



Mar 15, 2011 at 9:48 AM

Here's a modified version of SendCommentMail.cs for BE 2.0 (it goes in App_Code\Extensions).  If the comment is spam, it won't send the email.  Or if you are logged in and leaving a comment to your own post, it won't send the emails.  Untested, but should work as I describe.

#region using

using System;
using System.Net.Mail;
using System.Text;
using System.Threading;
using System.Web;

using BlogEngine.Core;
using BlogEngine.Core.Web.Controls;


/// <summary>
/// Sends an e-mail to the blog owner whenever a comment is added.
/// </summary>
[Extension("Sends an e-mail to the blog owner whenever a comment is added", "1.3", "BlogEngine.NET")]
public class SendCommentMail
    #region Constructors and Destructors

    /// <summary>
    /// Initializes static members of the <see cref="SendCommentMail"/> class. 
    ///     Hooks up an event handler to the Post.CommentAdded event.
    /// </summary>
    static SendCommentMail()
        Post.CommentAdded += PostCommentAdded;


    #region Methods

    /// <summary>
    /// Handles the CommentAdded event of the Post control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    private static void PostCommentAdded(object sender, EventArgs e)
        if (!BlogSettings.Instance.SendMailOnComment) { return; }

        var comment = (Comment)sender;
        if (comment == null) { return; }

        var post = comment.Parent as Post;
        if (post == null || post.CurrentUserOwns)

        if (comment.IsSpam)

        // Trackback and pingback comments don't have a '@' symbol in the e-mail field.
        var replyTo = comment.Email.Contains("@") ? comment.Email : BlogSettings.Instance.Email;
        var subject = " comment on ";

        switch (comment.Email)
            case "trackback":
                subject = " trackback on ";
            case "pingback":
                subject = " pingback on ";

        var defaultCulture = Utils.GetDefaultCulture();

        var args = new ServingEventArgs(comment.Content, ServingLocation.Email);
        Comment.OnServing(comment, args);
        var body = args.Body;
        body = body.Replace(Environment.NewLine, "<br />");
        body = body.Replace(string.Format("<img src=\"{0}", Utils.RelativeWebRoot), string.Format("<img src=\"{0}", Utils.AbsoluteWebRoot));

        var mail = new MailMessage
                From = new MailAddress(BlogSettings.Instance.Email),
                ReplyTo = new MailAddress(replyTo, HttpUtility.HtmlDecode(comment.Author)),
                Subject = BlogSettings.Instance.EmailSubjectPrefix + subject + post.Title

        var sb = new StringBuilder();
        sb.Append("<div style=\"font: 11px verdana, arial\">");
        sb.AppendFormat("{0}<br /><br />", body);
            "<strong>{0}</strong>: <a href=\"{1}#id_{2}\">{3}</a><br /><br />",
            Utils.Translate("post", null, defaultCulture),

        var deleteLink = string.Format("{0}?deletecomment={1}", post.AbsoluteLink, comment.Id);
            "<a href=\"{0}\">{1}</a>", deleteLink, Utils.Translate("delete", null, defaultCulture));

        if (BlogSettings.Instance.EnableCommentsModeration)
            var approveLink = string.Format("{0}?approvecomment={1}", post.AbsoluteLink, comment.Id);
                " | <a href=\"{0}\">{1}</a>", approveLink, Utils.Translate("approve", null, defaultCulture));

        sb.Append("<br />_______________________________________________________________________________<br />");
        sb.Append("<h3>Author information</h3>");
        sb.Append("<div style=\"font-size:10px;line-height:16px\">");
        sb.AppendFormat("<strong>Name:</strong> {0}<br />", comment.Author);
        sb.AppendFormat("<strong>E-mail:</strong> {0}<br />", comment.Email);
        sb.AppendFormat("<strong>Website:</strong> <a href=\"{0}\">{0}</a><br />", comment.Website);

        if (comment.Country != null)
            sb.AppendFormat("<strong>Country code:</strong> {0}<br />", comment.Country.ToUpperInvariant());

        if (HttpContext.Current != null)
            sb.AppendFormat("<strong>IP address:</strong> {0}<br />", HttpContext.Current.Request.UserHostAddress);
            sb.AppendFormat("<strong>User-agent:</strong> {0}", HttpContext.Current.Request.UserAgent);


        mail.Body = sb.ToString();


Mar 16, 2011 at 4:21 PM

So it should now send an email even if the comment is approved?