Send Rich Emails with Attachments from a SharePoint Designer Workflow

Related Products

PDF Converter

PDF Converter

Share

One of the most common (sub) tasks executed from a SharePoint workflow is the submission of an email. SharePoint ships with an Email Workflow Action out of the box, which is unfortunately very limited in its abilities. For example, it is not possible to include attachments, specify the From Address, set the Priority or specify the SMTP server to use.

In this blog post I’ll describe how to send an email from a workflow that automatically includes all files / attachments for the current item from a SharePoint Designer workflow using the Workflow Power Pack.

A quick introduction for those not familiar with the product: The Muhimbi Workflow Power Pack for SharePoint allows custom C# or VB.NET code to be embedded in SharePoint Designer Workflows without the need to resort to complex Visual Studio based workflows, the development of bespoke Workflow Activities or long development cycles.

Please note that this tutorial was originally written for SharePoint 2007. In newer versions of SharePoint please replace the ‘Build Dynamic String’ action with the ‘Set Workflow Variable’ action. Some familiarity with building basic workflows in SharePoint Designer and SharePoint programming in C# is required. Please see the Workflow Power Pack User Guide series for more details.

The solution presented below uses the standard Build Dynamic String Action to create the body of the email. This body is then passed as Parameter 1 to the Execute Custom Code Action. Parameter 2 is used to specify the To Address. This code is a great starting point for further customisation. For more details see the standard .net MailMessage and SmtpClient classes.

Create the workflow as follows:

  1. Download and install the Muhimbi Workflow Power Pack for SharePoint.

  2. Make sure you have the appropriate privileges to create workflows on a site collection.

  3. Create a new workflow using SharePoint Designer.

  4. On the Workflow definition screen associate the workflow with the list or library of your choice, tick the boxes next to both ‘ Automatically start…’ items and proceed to the next screen.

  5. Click the Actions button and insert the Build Dynamic String action .

  6. Click dynamic stringand enter an HTML based email.

  7. Click variable1 and create a new string based variable named mailMessage.

  8. Click the Actions button and insert the Execute Custom Code action .

  9. Click parameter 1, open the Workflow Lookup dialog and select Source: Workflow Data, Field: mailMessage.

  10. Click parameter 2 end enter the address to send the email to. Naturally this could be a lookup value as well.

  11. Insert the following C# based code by clicking this code.

  12. Close the Workflow Designer and add an item to your list or library to trigger the workflow.

    emailAttachments

The code in this example is a great starting point for making further customisations. You may want to change which parameters are passed in or load the attachments from a different item (See this Knowledge Base Article) or even using an HTTP Request. The solution presented in this post also works very well when combined with one of our other postings: Automatically convert files to PDF using an e-mail enabled SharePoint Document Library

Labels: Articles, News, PDF Converter, Workflow

Have a Question?
We’re Always Happy to Help.

© Muhimbi Ltd. 2008 - 2024
This website uses cookies to ensure you get the best experience. Learn more