Using a Render Task a developer can hook into the rendering process of the email and make changes to the message body/subject and the MailMessage-object itself. This can be used to add attachments, custom headers, or to replace/update content in the email.
Newsletter Studio uses Render Tasks to:
Developers can create render tasks and register them during startup. Just implement IRenderTask
, we will call the Process()
method once for each recipient. Be aware that any heavy work inside a Render Task will slow down the rendering and send-out process.
using NewsletterStudio.Core.Rendering;
using NewsletterStudio.Core.Rendering.Tasks;
using NewsletterStudio.Core.Sending;
namespace Demo.Web.Extensions.RenderTask;
public class AddAttachmentRenderTask : IRenderTask
{
public void Process(RenderTaskProcessingResult result, RenderingUniqueContext context)
{
context.EmailMessage.Attachments.Add(GetAttachmentFor(context.Recipient));
}
private EmailAttachment GetAttachmentFor(IRecipientDataModel recipientDataModel)
{
using var stream = File.OpenRead("c:\\temp\\invoice.pdf");
return new EmailAttachment("Invoice123.pdf", stream);
}
}
We also need to register the Render Task during application startup
using NewsletterStudio.Core.Composing;
using Umbraco.Cms.Core.Composing;
namespace Demo.Web.Extensions.RenderTask;
public class MySiteComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.NewsletterStudio().RenderTasks.Append<AddAttachmentRenderTask>();
}
}
It's also possible to remove/replace the core Render Tasks. Here is an example of how to inactivate all the tracking:
public class MySiteComposer : IComposer {
public void Compose(IUmbracoBuilder builder)
{
builder.NewsletterStudio().RenderTasks.Remove<AddTrackingPixelRenderTask>();
builder.NewsletterStudio().RenderTasks.Remove<AddClickTagsRenderTask>();
}
}
This will of course mean that any reports will not work.