One of the common errors many people seem to have when creating a SharePoint Workflow is with the SendEmailActivity. When your task task executes you recieve an error message:

The error message is frustrating because you know you’ve setup your outgoing e-mail settings in Central Administration, and your task notification and alert emails work fine. Many users suggest creating a custom code activity to just send the email manually, after all, the code to send an email with the System.Mail class is quite simple, however it’s a little taunting to have the task available to you, but not be able to use it. I found a few articles on the MSDN blogs that indicated the problem only occurs when you nest the activity in another activity, which in most Workflow Scenario’s you would. In my case I had the workflow activity nested in an IF/ELSE activity. I never tested this but regardless I needed it to work.

In my original code I set the SendEmailActivity properties from the previous tasks completed event as shown below:

string emailBody = this.SendExternalCollaborationEmailTask_Changed_AfterProperties.ExtendedProperties["emailBody"].ToString();
string emailSubject = this.SendExternalCollaborationEmailTask_Changed_AfterProperties.ExtendedProperties["emailSubject"].ToString();
string emailTo = this.SendExternalCollaborationEmailTask_Changed_AfterProperties.ExtendedProperties["emailTo"].ToString();
string emailCC = this.SendExternalCollaborationEmailTask_Changed_AfterProperties.ExtendedProperties["emailCC"].ToString();     

this.SendExternalCollaborationEmail.To = emailTo;
this.SendExternalCollaborationEmail.CC = emailCC;
this.SendExternalCollaborationEmail.Subject = emailSubject;
this.SendExternalCollaborationEmail.Body = emailBody; 

 

By changing the properties of the SendEmailActivity to use a Global Property and setting the Global Property value in your code the email will work.

Posted by Chris Buchanan

Leave a reply

Your email address will not be published. Required fields are marked *