Auto-subscribe author of page when comments are added in Message Board web part

Lawrence LeFebour asked on September 22, 2017 15:48

Is there a way to automatically notify or subscribe the author of a page when a comment is added to a Message Board web part on the page? The 'subscribe' functionality is available on-demand, but I'd like to automatically notify the author instead of having them need to subscribe manually.

Recent Answers


Trevor Fayas answered on September 22, 2017 19:32

I don't see any way through the settings i'm afraid.

You can set the Board as moderated and set the owner as a moderator when you create a new board, but i think that also then requires that new posts be approved.

What version of Kentico are you on, and do you want the author to receive the confirmation email of the subscription or just auto-subscribe?

0 votesVote for this answer Mark as a Correct answer

Lawrence LeFebour answered on September 22, 2017 20:41

Thanks Trevor, we're using v8.2. So ideally we don't want to have moderation or approvals - this is for an internal instance of Kentico within our company. The goal would be to have a user be able to add a comment to a page, and upon submission the author of the page would be notified. The author does not need to be notified when a user subscribes to a message board.

0 votesVote for this answer Mark as a Correct answer

Lawrence LeFebour answered on September 22, 2017 21:31

Currently we are using 'Public Message Board' as the Message Board Owner. Would there be a way to set the Message Board Owner to the page author, and would that enable easier notification of the page owner about a new message?

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on September 25, 2017 16:10 (last edited on September 25, 2017 16:10)

Okay so what i want you to do is the following:

1: Create a new Email Template in Kentico (Kentico > Email Templates) , this will be your email to the administrator of a post. Set the code name for it to "NewMessageOnBoardToAdmin"

2: Create a new Class and place it in your App_Code folder called "CustomModuleLoader.cs" with the text below:

using CMS.Base;
using CMS.MessageBoards;
using CMS.Membership;
using CMS.EmailEngine;
using CMS.SiteProvider;
using CMS.EmailEngine;
[CustomModuleLoader]
public partial class CMSModuleLoader
{
    /// <summary>
    /// Attribute class that ensures the loading of custom handlers.
    /// </summary>
    private class CustomModuleLoaderAttribute : CMSLoaderAttribute
    {
        /// <summary>
        /// The system executes the Init method of the CMSModuleLoader attributes when the application starts.
        /// </summary>
        public override void Init()
        {
            // Assigns custom handlers to events
            BoardMessageInfo.TYPEINFO.Events.Insert.After += BoardMessageInsert_After;
        }

        void BoardMessageInsert_After(object sender, CMS.DataEngine.ObjectEventArgs e)
        {
            BoardMessageInfo MessageObject = (BoardMessageInfo)e.Object;
            // Get the message board so we can get the author
            BoardInfo BoardObject = BoardInfoProvider.GetBoardInfo(MessageObject.MessageBoardID);
            // Get the Author user
            UserInfo BoardAuthorObject = UserInfoProvider.GetUserInfo(BoardObject.BoardUserID);
            // Build Email
            EmailMessage EmailToBoardAdmin = new EmailMessage();
            // Set the recipient to the board author
            EmailToBoardAdmin.Recipients = BoardAuthorObject.Email;
            // Send the email using the email template.
            EmailSender.SendEmail(SiteContext.CurrentSiteName, EmailToBoardAdmin, "NewMessageOnBoardToAdmin", null, false);

        } 
    }
}

For further reading, i would highly recommend you familiarize yourself with Kentico's Global Events.

https://docs.kentico.com/k82/custom-development/handling-global-events

Each Class's TYPEINFO has events for various tasks, this is an easy way to automate :)

0 votesVote for this answer Mark as a Correct answer

Lawrence LeFebour answered on September 25, 2017 17:31

Thanks for the great suggestion & insight Trevor. We'll try implementing this and reply to the thread.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.