1

I have a workflow that I have created in Visual Studio 2010 for publishing to my SharePoint 2010 site.

It's for a list I created and the workflow itself is pretty simple. A while loop that contains a sequence activity for workflow item changed, with some if-else logic. I have 4 branches on my if-else tree, three of which contain a "sendEmail" action from the toolbox. The workflow is set to activate when new items are added.

If I try and meet the criteria for any of the e-mail activities, the Workflow spits an event of type Error, with a user ID of "System Account" to the Workflow status log of "The e-mail message cannot be sent. Make sure the outgoing e-mail settings for the server are configured correctly." Now, I know for a fact that the outgoing settings are correct for the mail server: I have added alerts for new items/item changes and get those from the SP server just fine. I have Googled around around and seen something that suggests that this may be a change made in SP 1. I was so frustrated I went ahead and made a new VM with SharePoint 2010 that is the base RTM without SP1 and I still get the issue. I designed a simple workflow in SharePoint designer and the e-mail notifications from that workflow also work. I saw another post that suggested making sure you have a valid e-mail in the Users table of the WSS_Content database for the system account, which I have also done and still to no avail.

Am I doing something wrong? Does the sendemail action in the Visual Studio toolbox just not work for a custom sequential workflow? All I did to push the solution was "Deploy Solution", is there some other way to ensure it is being deployed with "Full Trust"? Finally, if it is absolutely not possible to just use the sendEmail action, does anyone have any suggestions on how best to go about it? I am self-admittedly a novice at best, so I haven't ruled out the fact that I may be missing something fairly obvious. Any help/insight/tips someone could offer me to help me avoid pulling all of my hair out would be HUGELY appreciated.

For reference my workflow1.cs is below:

    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Collections;
    using System.Drawing;
    using System.Linq;
    using System.Workflow.ComponentModel.Compiler;
    using System.Workflow.ComponentModel.Serialization;
    using System.Workflow.ComponentModel;
    using System.Workflow.ComponentModel.Design;
    using System.Workflow.Runtime;
    using System.Workflow.Activities;
    using System.Workflow.Activities.Rules;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Workflow;
    using Microsoft.SharePoint.WorkflowActions;

    namespace WorkOrderProcessing.Workflow1
    {
        public sealed partial class Workflow1 : SequentialWorkflowActivity
        {
            public Workflow1()
            {
                InitializeComponent();
            }

            public Guid workflowId = default(System.Guid);
            public SPWorkflowActivationProperties workflowProperties = new         SPWorkflowActivationProperties();

            private void WhileOne(object sender, ConditionalEventArgs e)
            {
                e.Result = true;
            }

            private void sendEmailToAssignee_MethodInvoking(object sender, EventArgs e)
            {
                SPListItem wfItem = onWorkflowActivated1.WorkflowProperties.Item;
                SPFieldUser assignedTo = (SPFieldUser)wfItem.Fields["Assigned To"];

                SPFieldUserValue user = (SPFieldUserValue)assignedTo.GetFieldValue(
                    wfItem["Assigned To"].ToString());
                string assigneeEmail = user.User.Email;

                sendEmailToAssignee.To = assigneeEmail;
                sendEmailToAssignee.Subject = "New work order has been created.";
                sendEmailToAssignee.Body = "Work order number " +
                    onWorkflowActivated1.WorkflowProperties.Item.ID +
                    " has just been created and assigned to you.";
            }

            private void sendEmailToRequestorHold_MethodInvoking(object sender, EventArgs e)
            {
                sendEmailToRequestorHold.To =         onWorkflowActivated1.WorkflowProperties.OriginatorEmail;
                sendEmailToRequestorHold.Subject = "Work order put on hold";
                sendEmailToRequestorHold.Body = "Work order number " +
                    onWorkflowActivated1.WorkflowProperties.Item.ID +
                    " has been put on hold. Please contact the maintenance help desk.";
            }

            private void sendEmailToRequestorComp_MethodInvoking(object sender, EventArgs e)
            {
                sendEmailToRequestorComp.To = onWorkflowActivated1.WorkflowProperties.OriginatorEmail;
                sendEmailToRequestorComp.Subject = "Work order has been completed";
                sendEmailToRequestorComp.Body = "Work order number " +
                    onWorkflowActivated1.WorkflowProperties.Item.ID +
                    " has been completed.";
            }

            public Hashtable onWorkflowItemChanged1_AfterProperties1 = new System.Collections.Hashtable();
            public Hashtable onWorkflowItemChanged1_BeforeProperties1 = new System.Collections.Hashtable();

            private void HasStatusChanged(object sender, ConditionalEventArgs e)
            {
                string astatus = onWorkflowItemChanged1_AfterProperties1["Status"].ToString();
                if (onWorkflowItemChanged1_BeforeProperties1["Status"] == null)
                {
                    e.Result = false;
                    return;
                }

                string bstatus = onWorkflowItemChanged1_BeforeProperties1["Status"].ToString();

                if (bstatus == astatus)
                    e.Result = true;
                else
                    e.Result = false;
            }

            private void IsStatusPendingCompletion(object sender, ConditionalEventArgs e)
            {
                string astatus = onWorkflowItemChanged1_AfterProperties1["Status"].ToString();
                if (astatus == "Pending Completion")
                    e.Result = true;
                else
                    e.Result = false;
            }

            private void IsStatusOnHold(object sender, ConditionalEventArgs e)
            {
                string astatus = onWorkflowItemChanged1_AfterProperties1["Status"].ToString();
                if (astatus == "On Hold")
                    e.Result = true;
                else
                    e.Result = false;
            }

            private void IsStatusCompleted(object sender, ConditionalEventArgs e)
            {
                string astatus =         onWorkflowItemChanged1_AfterProperties1["Status"].ToString();
                if (astatus == "Completed")
                    e.Result = true;
                else
                    e.Result = false;
            }
        }
    }
1

You need to create new fields for sendEmail method: right click on sendEmail (in my example is sendEmailtoInvestivatingIssue_Assignee) and select Properties, in the Mics select To, and click on the yellow database icon.

Select Bind to new member and check on New Field -->OK

Repeat for Subject, From, Body, ....

After created your code will have these lines

public String sendEmailtoInvestigatingIssue_Assignee_Body1 = default(System.String);
public String sendEmailtoInvestigatingIssue_Assignee_From1 = default(System.String);
public String sendEmailtoInvestigatingIssue_Assignee_Subject1 = default(System.String);
public String sendEmailtoInvestigatingIssue_Assignee_To1 = default(System.String);

Then modify your sendEmailtoInvestivatingIssue_Assignee procedure as follows

private void sendEmailtoInvestigatingIssue_Assignee_MethodInvoking(object sender, EventArgs e)
    {


        SPListItem wfitem = onWorkflowActivated1.WorkflowProperties.Item;
        SPFieldUser sendToAgreedPerson = (SPFieldUser)wfitem.Fields.GetField("Investigate Action Assigned To");
        SPFieldUserValueCollection userFVCollection = (SPFieldUserValueCollection)sendToAgreedPerson.GetFieldValue(wfitem["Investigate Action Assigned To"].ToString());

        string agreedPersonEmail = "";

        foreach (SPFieldUserValue userFV in userFVCollection)
        {
            string str1 = userFV.User.Email;
            agreedPersonEmail += str1 + ";";
        }

        sendEmailtoInvestigatingIssue_Assignee_From1 = "system@system.com";
        sendEmailtoInvestigatingIssue_Assignee_To1 = agreedPersonEmail;
        sendEmailtoInvestigatingIssue_Assignee_Subject1 = "Investigating Issue " + onWorkflowActivated1.WorkflowProperties.Item.Title + " has just been created.";
        sendEmailtoInvestigatingIssue_Assignee_Body1 = "Investigating Issue " + onWorkflowActivated1.WorkflowProperties.Item.Title + " has just been created.";


        sendEmailtoInvestigatingIssue_Assignee.From = sendEmailtoInvestigatingIssue_Assignee_From1;
        sendEmailtoInvestigatingIssue_Assignee.To = sendEmailtoInvestigatingIssue_Assignee_To1;
        sendEmailtoInvestigatingIssue_Assignee.Subject = sendEmailtoInvestigatingIssue_Assignee_Subject1;
        sendEmailtoInvestigatingIssue_Assignee.Body = sendEmailtoInvestigatingIssue_Assignee_Body1;


    }
0

I have faced this issue before with workflows inside Visual Studio and if you tested the workflow with another user in the directory that has a valid email most probably the workflow will work. I wasn't able to fix it for System Account

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.