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["MyFieldNamewhere:"] = parsedInitData. MyFieldName;
- 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.
- Most commonly of all, use a custom code activity to send an email. There are 2 variations:
-the more conventional way, via your own SMTP server, not even using SP to send the email in any way.
-calling the following function:SPUtility.SendEmail(SPWeb Web, bool fAppendHtmlTag, bool fHtmlEncode, string to, string subject, string htmlbody)
(http://forums.msdn.microsoft.com/en-US/sharepointworkflow/thread/22f41ab8-4f8b-4e19-8752-faaa1ca19b07/) - If the problem is only with Tasks that won't send email rather than SendEmail activities per se, then use SendEmail activities instead (http://forums.msdn.microsoft.com/en-US/sharepointworkflow/thread/6e848a25-019d-4220-aff6-c535da933e0f/).
- Use a Sequential workflow rather than a State Machine workflow (http://forums.msdn.microsoft.com/en-US/sharepointworkflow/thread/6e848a25-019d-4220-aff6-c535da933e0f/).
- Bind all the necessary Properties to some variable in VS's Properties window while using Workflow Designer instead of setting them in code (e.g. MyCustomActivity.SendEmailActivity.Subject = "The Subject") (http://spschris.blogspot.com/2008/03/e-mail-message-cannot-be-sent-make-sure.html)
- (My favorite!) Who needs abstraction? Open Pandora's box by moving all SendEmail activities out of your custom composite activities and into your Workflow (at the top level). (http://forums.msdn.microsoft.com/en-US/sharepointworkflow/thread/22f41ab8-4f8b-4e19-8752-faaa1ca19b07/)
2 comments:
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.
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?
Post a Comment