EPiServer workflows – emails not being sent

The most commonly used workflow in EPiServer is the Sequential approval workflow.

It is primarily used to assign tasks and send notifications through the various stages of page publication.

Troubleshooting workflows is no easy task. You typically have to enable Windows Workflow Foundation diagnostics and examine the logs.

You can achieve this by adding the following element to your web.config:

      <add name="System.Workflow.Runtime" value="All" />
      <add name="System.Workflow.Runtime.Hosting" value="All" />
      <add name="System.Workflow.Runtime.Tracking" value="All" />
      <add name="System.Workflow.Activities" value="All" />
      <add name="System.Workflow.Activities.Rules" value="All" />
      <add name="System.Workflow LogToTraceListeners" value="0" />
      <add name="System.Workflow LogToFile" value="1" />
    <trace autoflush="true" indentsize="4">
        <add name="customListener"
         initializeData="WFTrace.log" />

You will find a log file called “WFTrace.log” in the root of your website with diagnostic information.

A problem we faced in one of our projects was around EPiServer tasks not being created and email notifications not being sent. Errors similar to the ones below were common in the error logs:

System.Workflow.Runtime Error: 1 : Execute of Activity createTask1 threw System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at EPiServer.Personalization.Task.SendMail(String fromUser, String toUser, String mailSubject)
   at EPiServer.Personalization.Task.SendNotification()
   at EPiServer.Personalization.Task.Save(Boolean sendMailNotification)
   at EPiServer.WorkflowFoundation.InstanceHandler.CreateTaskForInstance(Guid workflowInstanceId, String assignedTo, String subject, String description, DateTime dueDate, PageReference pageLink, Boolean notifyByEmail, Boolean logAction, Boolean activityRelated, String eventActivityName, Dictionary`2 stateBag)
   at EPiServer.WorkflowFoundation.Services.CommunicationService.CreateTask(String AssignTo, String TaskSubject, String TaskDescription, DateTime DueDate, PageReference PageLink, String EventActivityName, Boolean NotifyByEmail, Boolean LogAction, Boolean ActivityRelated, Dictionary`2 StateBag, Guid InstanceId)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.Workflow.Activities.CallExternalMethodActivity.Execute(ActivityExecutionContext executionContext)
   at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext)
   at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)

In the end, the solution was rather simple: Do not forget to add “*” in the host names list of your website.