JD

24 February 2012

Sending an email with an attachment from Workflow Foundation

The problem:

The SendEmailActivity in WF sucks… because you can’t send an email with attachments from it.

I want to be able to send an email from a SharePoint WorkFlow, using the SP Outbound Mail Service and adding some attachments to the message.

The workaround:

Use the .Net MailMessage class (System.Net.Mail) and a Code activity to send the email:

Non-SharePoint example:

SharePoint example:

SharePoint Gotcha’s

SharePoint’s smtp server must be configured in Central Admin, otherwise you will get a NullReferenceException at web.Site.WebApplication.OutboundMailServiceInstance

Restart the SharePoint Timer Service to refresh it’s assembly cache if the workflow does not kick in

SPContext is not available in the Timer Job Context (under which the WF will run)

Get the source code here


← Back