Try Now
More in this section

Forums / General Discussions / Blog Comment Notification

Blog Comment Notification

3 posts, 0 answered
  1. Andy Smith
    Andy Smith avatar
    1 posts
    25 Sep 2009
    21 Jul 2010
    Link to this post

    Does anyone know a way to setup an email notification for blog comments?

    I know there is some customization with email notification, as we've done some of that with workflow. Hoping there is a similar set up for blog comments.

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    19 Oct 2016
    22 Jul 2010
    Link to this post
    Hello Andy Smith,

    You have to create a custom class that inherits from BlogComments. There override InitializeControls and subscribe for this.SubmitButton.Click event. Inside Click event you can add your logic that will send a notification.

    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Cameron
    Cameron avatar
    42 posts
    27 Jul 2009
    30 Jul 2010
    Link to this post
    Here's some code that I was able to use by placing in the global.asax file. I have a lot of it commented out for my use, but if you look through all of the lines it might help. What this does for me is send an e-mail to one e-mail address with the blog comment whenever a comment is made.

    /// <summary>
    /// Sends an email to Sitefinity Admins and other blog post commenters when a blog post comment is created or updated.
    /// </summary>
    public void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e)
        //// Only execute if a comment is being created.
        if (e.CommandName == "CreateComment")
            Telerik.Cms.Engine.Data.Comment postedComment = e.CommandArguments as Telerik.Cms.Engine.Data.Comment;
            postedComment.Author = HttpContext.Current.User.Identity.Name;
            //get the current user's First and Last names
            //ProfileBase profile = ProfileBase.Create(HttpContext.Current.User.Identity.Name);
            //string FirstName = profile.GetPropertyValue("FirstName").ToString();
            //string LastName = profile.GetPropertyValue("LastName").ToString();
            //postedComment.Author = FirstName;
            string smtpServer = "mymailserver.com";
            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(smtpServer);
            System.Net.NetworkCredential basicAuthenticationInfo = new
               System.Net.NetworkCredential("user", "password");
            client.Credentials = basicAuthenticationInfo;
            //client.EnableSsl = true;
            // Create Blog Comment Email
            System.Net.Mail.MailMessage message = CreateBlogCommentEmail(postedComment);
            // Get email recipients (admins & other blog commenters) and eliminate duplicates
            var EmailAddresses = new System.Collections.Generic.List<System.Net.Mail.MailAddress>();
            GetCommenterEmailAddresses(EmailAddresses, postedComment);
            // Send emails
            //foreach (System.Net.Mail.MailAddress mailAddress in EmailAddresses)
            //   try
            //    {
            //        message.To.Clear();
            //        message.To.Add(mailAddress);
            //        client.Send(message);
            //    }
            //    catch
            //    {
            //        // Handle the email sending error
            //    }
                //Handle error
    /// <summary>
    /// Creates the blog comments update email that will be sent.
    /// </summary>
    private System.Net.Mail.MailMessage CreateBlogCommentEmail(Telerik.Cms.Engine.Data.Comment postedComment)
        // Get Blog Post Title and URL
        string postTitle = postedComment.Parent.GetMetaData("Title").ToString();
        string postUrl = FixupUrl("~/blogs" + postedComment.Parent.UrlWithExtension);
        // Create Mail Message
        System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
        message.IsBodyHtml = true;
        message.From = new System.Net.Mail.MailAddress("noreply@mycompany.com", "Blog Update");
        message.Subject = "New comment to: " + postTitle;
        string body =
            "<p>A new comment has been added to <strong>" + postTitle + "</strong></p>\n" +
            "<p><a href=\"" + postUrl + "\">" + postUrl + "</a></p>\n" +
            "<p><strong>Comment:</strong></p>\n" +
            "<p>" + postedComment.Author + " wrote:</p>\n" +
            "<p>" + postedComment.Text + "</p>\n";
        message.Body = body;
        return message;
    /// <summary>
    /// Get email addresses for all Sitefinity users in the Administrators role.
    /// </summary>
    private void GetAdminEmailAddresses(System.Collections.Generic.List<System.Net.Mail.MailAddress> EmailAddresses)
                    EmailAddresses.Add(new System.Net.Mail.MailAddress("portaladmin@mycompany.com"));
    /// <summary>
    /// Get email addresses for other blog post commenters
    /// </summary>
    private void GetCommenterEmailAddresses(System.Collections.Generic.List<System.Net.Mail.MailAddress> EmailAddresses, Telerik.Cms.Engine.Data.Comment postedComment)
        foreach (Telerik.Cms.Engine.Data.Comment comment in postedComment.Parent.Comments)
            if (String.IsNullOrEmpty(comment.Email) == false)
                // Make sure the email address hasn't already been added.
                var query = from a in EmailAddresses
                            where a.Address == comment.Email
                            select a;
                if (query.Any() == false)
                    EmailAddresses.Add(new System.Net.Mail.MailAddress(comment.Email, comment.Author));

Register for webinar
3 posts, 0 answered