Friday, January 2, 2009

SPD Workflow: How to create a formatted body for the Send Email task?

A. Overview

The Send Email is a very popular action for SPD workflow developers. Unfortunately, the Editor of the e-mail body doesn't contain any formatting tools. That's a lot of luxury to ask for. But as the need arises, I have written this article to provide the steps for creating formatted e-mail bodies in the Send Email action.

I have taken the idea and some of the content of this article from an Office Online video tutorial with the title Watch this: Design a document review workflow solution.


B. Design the HTML needed in the body

1. Open Microsoft Office SharePoint Designer 2007.
2. Click File > New > HTML, in order to create a new HTML page.
3. A new panel opens. In the bottom left corner of this panel, make sure that the Split View is selected, as shown in the following figure.


IMPORTANT NOTE:
There are two considerations when you use HTML in workflows:

Consideration 1:
Workflow e-mails do not support class-based styles. All the formatting must be done using inline styles.
The following configuration steps should be performed:
- Click the Style Application icon on the bottom bar.
- Make sure that Style Application is set to Manual and the Target Rule is set to New Inline Style.


Consideration 2:
Any white space will affect how the designed HTML will be displayed. Therefore, it is recommended to remove it.
This can be done easily by performing these steps:
- Click Tools > Optimize HTML.
- In the Remove Whitespace section, select HTML all whitespace.


- Click OK. You can see that all the whitespace has been removed from the HTML code in the Code Pane.

To get the formatted text again, you should follow these steps:
- Select the text in the Code Pane and right-click it.
- Click Reformat HTML.


Now let's continue designing our HTML for the e-mail body.
5. Delete the default text in the Code Pane.
6. Copy and Paste the following text as an example in the Code Pane.



7. Click anywhere in the Design Pane, in order to see how your mail body would look like.
8. Perform the changes you wish.
9. Now remove the whitespace as explained in the previous Note section.
10. Copy your HTML code to a text file and save it, in order to be used later in the workflow.


C. Create the workflow

1. Click File > Open Site.
2. Enter the URL of the site containing an announcement list, on which we shall perform our test.
3. Now click File > New > Workflow.
4. On the Define your new workflow page, enter the following data:
  • Name: FormattingMails
  • Attachment List: Announcements
  • Start Options: Automatically start this workflow when a new item is created
5. Click Next, in order to start designing the workflow steps.
6. Enter Send formatted Mail Body as the Step Name.
7. In the Actions section, select the action Send an Email.
8. Click the this message link.
9. Fill the To and Subject fields with appropriate values.
10. Paste the HTML code which was designed in section B into the Body area.
11. Repalce the fields marked by [*****LOOKUP******] with the correct values using the Lookup wizard.


12. Click OK to close the message builder.
13. Click Finish to save and publish the workflow.


D. Test the solution

1. Browse the site containing the annoucenemnts list to which the workflow was attached.
2. Open the Annoucements list.
3. Create a new entry.
4. Check the body of the sent e-mail notification.

4 comments:

Greg O said...

Great article and great blog. Shame it doesn't seem to be updated any more :(

Greg
___________________________________
Sharepoint Resource Center
http://sharepointresourcecenter.com

AJCGirl said...

This article has been a GREAT HELP! Please come back! We need more great Sharepoint Articles like this!

Anonymous said...

Wow what an awesome post. This helped me create really professional looking email notifications in SharePoint. I was also able to use this same type of html code for my SysAid email notifications. Thx Samar!

Samar Hossam said...

Hello everyone,

Thanks for your nice comments. I am really glad that you found this article helpful.
Unfortunately, I am currently involved in projects that don't use SharePoint. That's why there are no new articles added to this blog for a while now.

Best regards,
Samar