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;
}
}
}