I've tried a few things on here and I'm a bit stuck. I'm trying to send a notification email out to members when a node is published - basically, a user subscribes and gets an email when a new node is published.
It would be helpful is someone could point me in the right direction.
Hi Darren,
You can hook into the publishing event and fire off emails from there. I usually include a true/false property on the article so I can control whether it should be sent out or not (and un-tick the property as part of the even hookup). You could also include a label property and set it's value to the date/time the article was sent out if you wanted to.
With regard to the message format; you can design an email-only template for the article and render it as the message body
Here's an example for you:
public class TargetedContentEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentService.Published += ContentService_Published;
base.ApplicationStarted(umbracoApplication, applicationContext);
}
void ContentService_Published(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<Umbraco.Core.Models.IContent> e)
{
foreach (var publishedEntity in e.PublishedEntities)
{
if (NotificationsPending(publishedEntity))
{
// Send out email to all subscribers
Library.TargetedContent.SendEmail(publishedEntity)
}
}
}
bool NotificationsPending(IContent content)
{
return content.HasProperty("notifySubscribers") && content.GetValue("notifySubscribers").ToString() == "1";
}
}
This is borrowed (and simplified) from the refactored.Subscriptions package (available on Nuget) - it's not overly well documented, but it handles member subscriptions including email account validation and sending out articles to subscribers.
The Library.TargetedContent.SendMail method (in the refactored.Subscriptions package) grabs a list of subscribers for the content, then renders the content in the alternative email template and sends it out to them on an individual basis (you can include field placeholders for personalisation etc.)
This method looks a little like this:
htmlTemplate = SubscriptionServices.Umbraco.RenderTemplate(content.Id, htmlTemplateId).ToString();
// If you want a text template as well you can render it separately
textTemplate = SubscriptionServices.Umbraco.RenderTemplate(content.Id, plainTextTemplateId).ToString();
// Resets the notification flag and sets the last notified date if applicable
UpdateNotificationStatus(content);
// Iterate through the list of subscribers and send out the email with the rendered templates
...
This looks good - however, probably beyond my skills ha ha. Where do I need to add these bits of code and do I need to download some additional software?
First off, what dotnet framework is your project targeting? You'll need to target 4.5 for the Refactored.Subscriptions package to work.
After that; it's just configuration - have a look in the /config directory for the Subscriptions.cpnfig file... you'll need to edit some of the settings there and there's a whole lot of changes you'll need to make to your Umbraco solution - data types, member types, alternative content templates, and a few pages need to be created to allow people to sign up and confirm their email address (if you want to go that far).
I'm afraid the documentation is really lacking on this package; I've not officially released it for public consumption; and I normally get paid to set this up in client sites so it's pretty much all in my head. I do consider this package to be under development still.
Firstly though, what's your use case for this? How do you anticipate this working in your solution; do you need to have people confirm their email address; can you automatically sign them up for updates as part of the registration process?
Do you need to send out notifications based on a member choosing to watch a particular article, or do you want to send a bunch of subscribers a new message every time you add content to a particular area of your site?
It's entirely possible this solution may not fit your needs, and in many cases you may be better off writing something specific, or engaging someone to do it for you...
Once we can acertain exactly what you want to achieve, I may be in a better position to help you, and could most likely tell you whether this solution will do it for you...
It's the latter - I want users to subscribe with an email address and name. When a given node is published I'd like an email sent out to all those subscribers saying a node has been published. The content of the node might be contained within the email too.
Thanks for all your time - its a big help. I've only been using Windows and Umbraco locally for a week, so please excuse my ignorance.
ok, so how far have you gotten - do you have the sign up forms?
It sounds like this package may do what you want; have you gotten everything to compile yet?
Once you do, you'll want to set up the Data type -
Targeted Subscription Content - this should be added to your Member Type that you're using for Subscribers. There are several pre-values on it that you'll need to configure including choosing the actual content node that contains the articles you want to send out to subscribers as well as the Template to render the node as the email body.
Then you can add the new Data Type to your Member Type properties.
With that done, you can create your subscribe/confirm/unsubscribe content nodes - there are a few pre-built Macro Scripts forms you can use but you'll need to create the actual Macros to take advantage of them yourself. The scripts are:
SubscriptionConfirmed.cshtml
UnsubscribeForm.cshtml
Once you've got your macros you can use them on general content pages within the site - I suggest setting up the following, but you can do whatever suits and just update the config file:
/subscribe/confirmed - use the first macro file above
/subscribe/unsubscribe - use the second macro file
If your urls are different to the above, update the configuration file.
You will need to add a few properties to your Document Type that you intend to use to create content you will be sending out to subscribers - these are:
subNotifySubscribers - true/false property
subLastNotified - Label property - is updated when the emails are sent out
There is also a subscriptionContentId property that should be added to whatever Document Type you are using for the subscribe page - the value of that property should be the page containing the articles that you want subscribers to receive.
That should get you going; there is some configuration of the email template as well, but if you get this far then we can cover that stuff.
Only just started out - still trying to get my head around it. I need to incorporate this into an existing site that I'm not sure of what the .NET version is. I think I might need a bit of professional help!
Notify member of node publish
Hi Folks,
I've tried a few things on here and I'm a bit stuck. I'm trying to send a notification email out to members when a node is published - basically, a user subscribes and gets an email when a new node is published.
It would be helpful is someone could point me in the right direction.
Thanks in advance. Darren
I think this might help - not sure where to bung this though!
Hi Darren, You can hook into the publishing event and fire off emails from there. I usually include a true/false property on the article so I can control whether it should be sent out or not (and un-tick the property as part of the even hookup). You could also include a label property and set it's value to the date/time the article was sent out if you wanted to.
With regard to the message format; you can design an email-only template for the article and render it as the message body
Here's an example for you: public class TargetedContentEventHandler : ApplicationEventHandler { protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { ContentService.Published += ContentService_Published; base.ApplicationStarted(umbracoApplication, applicationContext); }
This is borrowed (and simplified) from the refactored.Subscriptions package (available on Nuget) - it's not overly well documented, but it handles member subscriptions including email account validation and sending out articles to subscribers.
The
Library.TargetedContent.SendMail
method (in the refactored.Subscriptions package) grabs a list of subscribers for the content, then renders the content in the alternative email template and sends it out to them on an individual basis (you can include field placeholders for personalisation etc.)This method looks a little like this:
Hope this helps!
Mr Robert Foster
can you explain where exactly can i use or found that method executed when nodes published?
Hi Mus'ab,
See this article for reference: https://our.umbraco.com/Documentation/Reference/Events/Application-Startup-v7
Thx Mr Carlos i will check it
Hi Robert,
Thanks for your quick reply.
This looks good - however, probably beyond my skills ha ha. Where do I need to add these bits of code and do I need to download some additional software?
Thanks Darren
After a lot of googling - I've installed NuGet and tried to install this locally but I'm getting loads of errors - and a 500 error on my site.
Do you think I'm doing something wrong?
What is it you installed?
Aha - I see now.
First off, what dotnet framework is your project targeting? You'll need to target 4.5 for the Refactored.Subscriptions package to work.
After that; it's just configuration - have a look in the /config directory for the Subscriptions.cpnfig file... you'll need to edit some of the settings there and there's a whole lot of changes you'll need to make to your Umbraco solution - data types, member types, alternative content templates, and a few pages need to be created to allow people to sign up and confirm their email address (if you want to go that far).
I'm afraid the documentation is really lacking on this package; I've not officially released it for public consumption; and I normally get paid to set this up in client sites so it's pretty much all in my head. I do consider this package to be under development still.
Firstly though, what's your use case for this? How do you anticipate this working in your solution; do you need to have people confirm their email address; can you automatically sign them up for updates as part of the registration process?
Do you need to send out notifications based on a member choosing to watch a particular article, or do you want to send a bunch of subscribers a new message every time you add content to a particular area of your site?
It's entirely possible this solution may not fit your needs, and in many cases you may be better off writing something specific, or engaging someone to do it for you...
Once we can acertain exactly what you want to achieve, I may be in a better position to help you, and could most likely tell you whether this solution will do it for you...
Rob.
Hi Robert,
It's the latter - I want users to subscribe with an email address and name. When a given node is published I'd like an email sent out to all those subscribers saying a node has been published. The content of the node might be contained within the email too.
Thanks for all your time - its a big help. I've only been using Windows and Umbraco locally for a week, so please excuse my ignorance.
Kind Regards Darren
ok, so how far have you gotten - do you have the sign up forms?
It sounds like this package may do what you want; have you gotten everything to compile yet?
Once you do, you'll want to set up the Data type -
Then you can add the new Data Type to your Member Type properties.
With that done, you can create your subscribe/confirm/unsubscribe content nodes - there are a few pre-built Macro Scripts forms you can use but you'll need to create the actual Macros to take advantage of them yourself. The scripts are:
Once you've got your macros you can use them on general content pages within the site - I suggest setting up the following, but you can do whatever suits and just update the config file:
If your urls are different to the above, update the configuration file.
You will need to add a few properties to your Document Type that you intend to use to create content you will be sending out to subscribers - these are:
subNotifySubscribers
- true/false propertysubLastNotified
- Label property - is updated when the emails are sent outThere is also a
subscriptionContentId
property that should be added to whatever Document Type you are using for the subscribe page - the value of that property should be the page containing the articles that you want subscribers to receive.That should get you going; there is some configuration of the email template as well, but if you get this far then we can cover that stuff.
Rob.
Hi Rob,
Only just started out - still trying to get my head around it. I need to incorporate this into an existing site that I'm not sure of what the .NET version is. I think I might need a bit of professional help!
Will let you know how I get on.
Darren
ok, hopefully you can get it working - what version of Umbraco is the existing site built on?
I'm using a test install so I can hack away as much as necessary - so no damage to live jobs or anything.
D
is working on a reply...