Notification of Blog Comment
Is there a way for Sitefinity to send an email notification out when a comment is posted to a blog entry?
Sadly no...a notification system should be in early 2012...I've been pestering them for that one for a while
Sorry :/
The only thing we have right now is a marketplace addon which adds FORM submission notifications.
Is this part of Sitefinity yet?
Hello,
It is not available out of the box, but can be done with this customization.
Create a class in your solution and crete a custom comment class as in the sample below.
For blog comments:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Net.Mail;using Telerik.Sitefinity.Configuration;using Telerik.Sitefinity.Services;using System.Text;using Telerik.Sitefinity.Web.Mail;using System.ComponentModel; namespace SitefinityWebApp public class CustomComments : Telerik.Sitefinity.Modules.GenericContent.Web.UI.Views.CommentsDetailsView protected override void SubmitComment() base.SubmitComment(); var smtpSettings = Config.Get<SystemConfig>().SmtpSettings; MailMessage message = new MailMessage(); message.From = new MailAddress(smtpSettings.DefaultSenderEmailAddress); message.To.Add(new MailAddress("stanislav.velikov@telerik.com")); StringBuilder sb = new StringBuilder(); sb.AppendFormat("You have one new form response on form. The response is sent from IP address"); message.Subject = "Forms notification"; message.Body = sb.ToString(); message.IsBodyHtml = true; message.BodyEncoding = Encoding.Unicode; message.SubjectEncoding = Encoding.Unicode; EmailSender.Get().Send(message); Go to Administration->Settings->Advanced->ContentView->Controls->BlogCommentsFrontend->Views->CommentsDetailView-> find the textbox ViewType and enter in it the namespace.class of the class created (in my case SitefinityWebApp.CustomComments ).
This will send email for blog comments only. Following the same pattern the same class can be used to send comments for news, events
To receive the e-mail you mut have valid SMTP settings configured in Administration->Settings->Advanced->System->SMTP
Hi Stanislav Velikov,
While posting a comment the event get fired, but unfortunately i am not able to get the "Commented" information ex:(Name,Email,Comment Text). I need to send a mail with Commented information. Can u please help me around this?
Thanks
Hi Stanislav Velikov,
At the time of submittion, the "Comment" form not get validated. After the event fires on server side the validation get fired. Is this a bug?
Hi Mari,
This should retrieve the content of the form
protected override void SubmitComment() var content = this.ContentControl.Value.ToString(); var authorName = this.Page.Server.HtmlEncode(this.AuthorNameControl.Value.ToString()); base.SubmitComment(); Hi,
A better solution is to subscribe to sitefinity event when a comment has been created (here is the documentation for comments events) the submitted comment data is in the event arguments for the event.
Greetings,
Stanislav Velikov
the Telerik team
What's the best place to subscribe to this event, global.asax.cs, under Application_Start()?
For example:
Telerik.Sitefinity.Services.EventHub.Subscribe<Telerik.Sitefinity.Modules.GenericContent.Events.ICommentCreatingEvent>(evt => MySampleCommentNotificationMethod(evt));
???
Hello,
Yes this way the event subscription will be registered every time the application starts, here is a sample
protected void Application_Start(object sender, EventArgs e) Bootstrapper.Initialized += new EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(Bootstrapper_Initialized);void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e) EventHub.Subscribe<IDynamicContentUpdatedEvent>(evt => UpdatedEventHandler(evt)); EventHub.Subscribe<IDynamicContentCreatedEvent>(evt => CreatedEventHandler(evt));public void CreatedEventHandler(IDynamicContentCreatedEvent eventInfo) var userId = eventInfo.UserId; var creationDate = eventInfo.CreationDate; var dynamicContentItem = eventInfo.Item; var visible = eventInfo.Visible; //Your email logic upon item dynamic item creation.public void UpdatedEventHandler(IDynamicContentUpdatedEvent eventInfo) var userId = eventInfo.UserId; var modificationDate = eventInfo.ModificationDate; var dynamicContentItem = eventInfo.Item; var visible = eventInfo.Visible; //Your email logic upon item dynamic item update.Thanks for the reply. I think, however, I'm interested in seeing how this could be achieved with regular comment events, i.e., ICommentCreatingEvent. We're unable to intercept/handle this event.
For example, we're trying to handle the ICommentCreatingEvent for comments that are created again blog posts in order to send an email notification.
Hello,
If you are using sitefintiy 6.1 I indicate a problem executing comment events, those are executed with success in sitefintiy 6.2.
Regards,
Stanislav Velikov
Telerik