Skip to content

Instantly share code, notes, and snippets.

Created October 29, 2017 13:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
public class AttachmentRendertask : Services.RenderTasks.RenderTask
string _attachmentPath = String.Empty;
public override void ProcessPreRender(RenderResult renderResult, RenderTaskParameters parameters)
// This method is executed when the scheduled jobs web request is still running. This means that the UmbracoContext, ApplicationContext etc can still be used.
// Let's save the path to the attachment media file here.
// Check if this newsletter is connected to a content node (if the ContenNodeId-property has a value the letter is created from that node in the content section).
if (parameters.Newsletter.ContentNodeId.HasValue && parameters.Newsletter.ContentNodeId.Value > 0)
// Get this node as a IPublishedContent-object
var helper = new UmbracoHelper(UmbracoContext.Current);
var node = helper.TypedContent(parameters.Newsletter.ContentNodeId);
// Check that there is an attachment-property defined (this could be any name of the property, attachement is just an example).
if (!node.HasProperty("attachment") || node.GetPropertyValue<int>("attachment") <= 0)
var attachmentMediaId = node.GetPropertyValue<int>("attachment");
var property = helper.TypedMedia(attachmentMediaId);
_attachmentPath = HttpContext.Current.Server.MapPath(property.GetPropertyValue<string>("umbracoFile"));
public override void ProcessUniqueItem(RenderResult renderResult, RenderTaskUniqueItemParameters parameters)
if (!string.IsNullOrEmpty(_attachmentPath))
// add new attachment to the e-mail;
parameters.MailMessage.Attachments.Add(new Attachment(_attachmentPath));
Copy link

pedroadaodev commented Nov 18, 2019

Thanks for this render task,

Can you please add a comment in the beging of the file?

This is only possible if the newsletter is configured under the Content section in Umbraco
Enable this RenderTask by adding a new configuration on newsletterStudio.config under emailRenderingTasks
See more information on how to configure and enable RenderTasks
This will only work when send-it to a subscription list. Not available for testing.

I was missing this configuration

Best regards,

Copy link

Thanks for the feedback! I've updated the support article with some more details on this. Hope this make it more clear. All the best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment