Email Notification about New Comments
In 3.7, you would subscribe to the "Executing" event in the Global.asax like the below snippet. Is it similar in 4.0?
public
void
Application_Start(
object
sender, EventArgs e)
Telerik.Cms.Engine.ContentManager.Executing +=
new
EventHandler<Telerik.ExecutingEventArgs>(ContentManager_Executing);
public
void
ContentManager_Executing(
object
sender, Telerik.ExecutingEventArgs e)
// Only execute if a comment is being created.
if
(e.CommandName ==
"CreateComment"
)
// Code goes here!
I see there is a property called "EmailAuthor" when I go to "Administration > Settings > Advanced > News > Controls > NewsCommentsFrontend > Views > CommentsDetailsView > CommentsDefinition". Does this have anything to do with it (configuration instead of coding)?
Hi bemara57,
EmailAuthor - gets or sets a value indicating if author of the post will be notified via email when a new comment is submitted. If it is true the author of the post will be notified via email when a new comment is submitted; otherwise false.
Greetings,
Ivan Dimitrov
the Telerik team
Hello Ivan,
the below code for 3.7, please I need similar to it in 4.x version ?
public
void
Application_Start(
object
sender, EventArgs e)
Telerik.Cms.Engine.ContentManager.Executing +=
new
EventHandler<Telerik.ExecutingEventArgs>(ContentManager_Executing);
public
void
ContentManager_Executing(
object
sender, Telerik.ExecutingEventArgs e)
// Only execute if a comment is being created.
if
(e.CommandName ==
"CreateComment"
)
// Code goes here!
Hello Ivan,
the below code for 3.7, please I need similar to it in 4.x version ?
public
void
Application_Start(
object
sender, EventArgs e)
Telerik.Cms.Engine.ContentManager.Executing +=
new
EventHandler<Telerik.ExecutingEventArgs>(ContentManager_Executing);
public
void
ContentManager_Executing(
object
sender, Telerik.ExecutingEventArgs e)
// Only execute if a comment is being created.
if
(e.CommandName ==
"CreateComment"
)
// Code goes here!
Hello Romany,
Can you please check the following blog post.
Regards,
Boyan Barnev
the Telerik team
Dear Boyan,
I am facing a problem that the event with the same command name called multiple times
which if I want to send a notification email when a new news item created the email will sent 3 times
is there a way to solve this problem (in details solution please) ?
Thanks
Romany
Hi,
You can override the data provider and its public methods that are called once where needed and then replace the default data provider through configurations.
Regards,
Ivan Dimitrov
the Telerik team
Hello Ivan,
1- Please can you give me step by step with code, how to override the data provider for "News" to do the following job: when new item created send an email
2- on the following event in "News" I need to get the newely item created data (title, description) but always all propoerties are empty, why this ?
void Events_Executed(object sender, Telerik.ExecutedEventArgs e) |
Hi,
Ok, if we are not talking about sending notification when comment is posted, then you can use the workflow by modifying its templates. You should customize NotifyStateChanger EmailText in AnyContentApprovalWorkflow.xamlx. Then you have to map customized templates through Sitefinity/Administration/Settings/Advanced >> Workflows.We use Windows Workflow Foundation and these are the XAML files that you can modify in Visual Studio or another XML editor.
sample
public virtual bool NotfiyForNewItem(string name)
EmailSender sen = EmailSender.Get();
sen.Send(new MailMessage(new MailAddress("mail"), new MailAddress("address")));
return true;
Have in mind that in standard edition you can have the default workflow only . In the next level - Professional you may have conditional approval steps, safeguards, notifications etc. Here is a related post that you can follow.
If you want to override the data provider here is the code that you can use.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
Telerik.Sitefinity.Modules.News;
using
Telerik.Sitefinity.Modules.News.Data;
using
Telerik.Sitefinity.News.Model;
using
Telerik.Sitefinity.Security;
using
Telerik.Sitefinity.Model;
using
Telerik.Sitefinity.Localization;
using
Telerik.Sitefinity.Data;
namespace
Telerik.Sitefinity.Samples
public
class
SitefinityNewsDataProvider : OpenAccessNewsProvider
public
override
Telerik.Sitefinity.News.Model.NewsItem CreateNewsItem(Guid id)
//return base.CreateNewsItem(id); WE ARE NOT USING THE BASE
var newsItem =
new
NewsItem(
this
.ApplicationName, id);
newsItem.Owner = SecurityManager.GetCurrentUserId();
((IDataItem)newsItem).Provider =
this
;
var securityRoot =
this
.GetSecurityRoot();
if
(securityRoot !=
null
)
this
.providerDecorator.CreatePermissionInheritanceAssociation(securityRoot, newsItem);
else
var msg = Res.Get<SecurityResources>().NoSecurityRoot;
msg =
string
.Format(msg,
typeof
(NewsItem).AssemblyQualifiedName);
throw
new
InvalidOperationException(msg);
if
(id != Guid.Empty)
this
.GetContext().Add(newsItem);
// HERE SEND YOUR EMAIL. YOU HAVE THE NEWS ITEM OBJECT ADDED TO THE CONTEXT
return
newsItem;
Hi Ivan Dimitrov,
Hello,
The NewsItem has a property Status from which you should be able to identify ContentLifecycleStatus
- Master
- Temp
- Live
and send the email.
Kind regards,
Ivan Dimitrov
the Telerik team
Hi Ivan Dimitrov,
Thanks for your fast reply. In that case all the time i am getting the ContentLifecycleStatus status as "Master" and i am not able to get the "Live" item. Please can you suggest me?
Here is my code belloe:
public override Telerik.Sitefinity.News.Model.NewsItem CreateNewsItem(Guid id)
//return base.CreateNewsItem(id); WE ARE NOT USING THE BASE
var newsItem = new NewsItem(this.ApplicationName, id);
newsItem.Owner = SecurityManager.GetCurrentUserId();
((IDataItem)newsItem).Provider = this;
var securityRoot = this.GetSecurityRoot();
if (securityRoot != null)
this.providerDecorator.CreatePermissionInheritanceAssociation(securityRoot, newsItem);
else
var msg = Res.Get<SecurityResources>().NoSecurityRoot;
msg = string.Format(msg, typeof(NewsItem).AssemblyQualifiedName);
throw new InvalidOperationException(msg);
if (id != Guid.Empty)
this.GetContext().Add(newsItem);
if (newsItem.Status == ContentLifecycleStatus.Live)
string sTitle = newsItem.Title;
// HERE SEND YOUR EMAIL. YOU HAVE THE NEWS ITEM OBJECT ADDED TO THE CONTEXT
return newsItem;
Hi Ivan Dimitrov,
Is there any solution for the above code? Please reply me ASAP.
Thanks
I chose the second option to override CreateNewsItem function but my question now as following:
I created a class in the portal called SitefinityNewsDataProvider and override the function as below and go to sitefinity->Lists->settings to register the provider and created a new provider but I found the following fields
Name: SitefinityNewsDataProvider
Title:
ResourceClassID:
ProviderType: ?????????? what is the value for this field
because I tried to assign many values to it but my code didn't fire
Please advise
Thanks,
Romany