Note! You are looking at documentation for an old version of the package. Go here for the latest documentation.

Using a render task an developer can hook into the rendering process of the email and make changes to the message body/subject. This can be done both on an overall level and on each individual email (ie. personalization). This feature could for example be used to replace [sometext] inside the message with a value from some other source. All rendering that happens inside Newsletter Studio is built with render tasks and they are all configured inside the newsletterStudio.config.

 

Create a custom render task

Creating a custom render task is very straight forward. Just inherit the base class " NewsletterStudio.RenderTasks.RenderTask" and override these three methods:

  • ProcessPreRender This method will be invoked when a newsletter is about to be sent. Only once per letter - this could be used to make changes on an overall basis. Ie. It's here we replace relative links, add clicktracing, render url content, insert unsubscribe-links and so on.
  • ProcessPreview This method is the equivalent to PreRender but is only used when the letters is previewed. Here we exclude clicktracking, replace unsubscription with a # to prevent the unknown newsletter editor from trying to unsubscribe. Note. If this method is not overridden the base class will call PreRender instead so if it has the same code, no need to implement both.
  • ProcessUniqItem Will be called on each uniq render of an email. Here we replace [name] with the real name, we merge other personal fields into the content. Be aware! This method will not be used when you preview the newsletter as it requires a receiver. If you need to change the content in preview mode as well - implement the ProcessPreview()-method and create a generic result for preview only.


Note! When you're class is ready, put the DLL inside the bin-folder and add configure the render task in /config/newsletterStudio.config by adding a new child to the "emnailRenderingTasks"-list, something like this:

 

<emailRenderingTasks>
    ...
    <add name="AddCustomMailHeaders" type="MyApp.Namespace.AddCustomMailHeaders, MyApp" />
</emailRenderingTasks>


Be aware that "type" need to be the full name of the class (including namespace) followed by , and the assembly name. See the video below for details.

 

Parameters to render tasks

The render tasks are passed parameters for you to use in the creation of your task. You can use them in different ways, one way could be to add extra headers to the message that are sent, this is done in the "ProcessUniqItem"-method.
 

public class AddCustomMailHeaders : RenderTask
{
    .....
    public override void ProcessUniqItem(RenderResult renderResult, RenderTaskUniqItemParameters parameters)
    {
        parameters.MailMessage.Headers.Add("Custom", "Header");
    }
}






More articles on "Develop with Newsletter Studio"

Subscription Providers

Can be used to hook into other systems or data sources. Newsletter Studio will use the providers to fetch the needed information about the receivers. All current subscriptions options (Newsletter Studios native mailing list and Umbraco members) are build with providers and it's easy to implement you…

Read article

Frontend API

To interact with Newsletter Studio from the front end we provide a very simple API in the static class NewsletterStudio.Api. This class has several methods for adding and removing subscribers both from the built in subscriptions and from Umbraco's member section (it won't delete anything but it chan…

Read article

Events

Since version 1.4.5 and 2.1 Newletter Studio contains some events that you as a developer can use when you develop your solutions.  Event name v1.4.5+ v2.1+ NewsletterStudio.Services.SendNewsletterService.SendningInitializing Yes Yes NewsletterStudio.Services.SendNewsletterService.Sent Yes Ye…

Read article

Custom data fields

The default property fields for receivers in Newsletter Studio are: name, e-mail, subscribed date and status. But some clients want to add custom data to their contacts.Since version 2.1 we've decided to prepare the underlying data layer for this by adding a new property called “Data” on the Receive…

Read article

Working programmatically

There is a lot of things that can be done using the services and repositories that Newsletter Studio provides. You can explore these APIs using the "GlobalFactory" which is a service locator that the package uses internally. For example, you can access the Mailing List Repository like this: Newslett…

Read article