More in this section
Forums / General Discussions / Blog Comment Notification

Blog Comment Notification

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
3 posts, 0 answered
  1. Andy Smith
    Andy Smith avatar
    1 posts
    Registered:
    25 Sep 2009
    21 Jul 2010
    Link to this post
    Howdy,

    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.

    Thanks!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    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.

    Greetings,
    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. Susan
    Susan avatar
    42 posts
    Registered:
    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;
     
            // CHANGE THIS INFORMATION FOR YOUR SMTP SERVER !!!!!
            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>();
            GetAdminEmailAddresses(EmailAddresses);
            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
            //    }
            //}
            message.To.Clear();
            message.To.Add("portaladmin@mycompany.com");
             
            try
            {
                client.Send(message);
            }
            catch
            {
                //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