Wednesday, August 6, 2008

The e-mail message cannot be sent. Make sure the outgoing e-mail settings for the server are configured correctly.

When building a SharePoint workflow that sends email either via the SendEmail activity or the CreateTask activity (with taskProperties.SendEmailNotification = true), many workflows will receive the error message "The e-mail message cannot be sent. Make sure the outgoing e-mail settings for the server are configured correctly," even if email works elsewhere (e.g. outside the workflow).

I get this message for every task assigned in my workflow, but I know the "offending code" that causes this error. Generally, it is code that copies data from the filled-out initialization form into a task's ExtendedProperties (which will show up in the custom task form). (Also note that the custom Task form has all the same fields as the Initialization form, plus some. I copied and pasted the fields from the Initialization template to the Task template when desiging in InfoPath.)

Specifically, in an initialization routine called within onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e), I have several lines that look like the following:

taskProperties.ExtendedProperties["MyFieldName"] = parsedInitData.MyFieldName;
where:
  • taskProperties is a new SPWorkflowTaskProperties object to which MyCustomActivity.CreateTask_TaskProperties is assigned.
  • parsedInitData contains the data placed in the Initialization form that kicks off the workflow.
  • MyFieldName is the name of a field in said initialization form template, thus also a form in parsedInitData.
SOOO... I find that others have suggested the following workarounds:
What workarounds work for you all, my readers (all zero of you)? I shall investigate what to do in my specific situation today.

2 comments:

Pritish said...

Hi, I followed the approach outlined by Chris in one of your bullet points (http://spschris.blogspot.com/2008/03/e-mail-message-cannot-be-sent-make-sure.html) and it worked - miraculously. Note: I am using Visual Studio 2008 and developing custom workflows and this occurred (so the issue is not limited to SP Designer). Thanks for posting the variety of solutions you've found.

bigKenny said...

Cheers! I struggled with the CreateTask activity and SendEmailNotifications in the past and found my workaround here. I have a new problem with the SendEmail activity now. The From property is a string that takes some (bogus in my case) email address. My beef is that there is no way to control the "display name" that is associated with the From email address. SharePoint puts the title of the web on which the workflow is running as the From name. This is causing confusion with some of my users and the workflow in question is always has hundreds of instances running, so I can't go ripping out my SendEmail activities in favor of System.Net.Mail and the EmailAddress class where I can specify the display name. Any ideas of overriding this default?