Monday, December 14, 2015

Send email to external users in Sharepoint 2013 workflow

As you probably know Sharepoint 2013 supports 2 workflow platforms:

  • Workflows 2010
  • Workflows 2013

Using of workflows 2013 in Sharepoint 2013 requires installation and configuration of Workflow manager – there are many guides available in internet at the moment so I won’t add it there. It gives us many new useful features like loops. Unfortunately there are also some limitation comparing with 2010 workflows. For example it is not so simple now to sent emails to external users. In 2013 workflow when you add action Send email you should specify valid (resolvable) Sharepoint user with non-empty email, not email itself. It was done for security purposes. Because of this you can’t anymore send email to external users as simple as it was in workflows 2010 where you could just specify user’s email in To field.

In order to avoid this issue we used Plumsail’s Workflow Actions Pack. Please note that it is commercial product, prices are available on their web site. It also has trial 30-days version when you may try this product. Documentation available on Plumsail doesn’t provide all necessary information which is needed for making actions pack work, so I will describe several additional steps.

When you will install the package there will be number of new actions available in Sharepoint Designer 2013. One of them is “Send email with attachments (SMTP)” (there is also possibility to send email via Exchange, but I didn’t try it). In this action together with email settings (recipient, subject, body) you need to specify SMTP host, port, ssl usage. Note that you may only use those SMTP servers which work with authenticated users. And you need to specify credentials in Email and Password fields of the workflow action together with other SMTP parameters (initially Plumsail documentation mentioned that these parameters belong to Exchange user, but at the moment of writing of this post it was already fixed – good work from their support. Also in Email field it is not necessary to specify real email. Some SMTP servers authenticate users with separate user id, which is not email). If you will leave these fields empty you will get the following exception;

Global Exception LoggerException: System.NullReferenceException: Object reference not set to an instance of an object.    
at Plumsail.WFServices.Common.SmtpEmailRepository.I1e(String  )    
at Plumsail.WFServices.Common.SmtpEmailRepository.SendEmail(Email email)    
at Plumsail.WFServices.Services.ExchangeController.SendEmail(EmailSendRequest request)    
at SyncInvokeSendEmail(Object , Object[] , Object[] )    
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)    
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)    
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)    
at System.ServiceModel..Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)    
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

This is one of limitations, because you can’t use your internal company SMTP server which is available only internally and doesn’t require authentication.

If you specified all SMTP settings with Email and Password you may also get the following error:

Exception: Could not load file or assembly 'Microsoft.Exchange.WebServices, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

In order to fix it you need to install MS Exchange web services API, which is available here. It may also confuse a bit, because Exchange API is needed in scenarios when you use SMTP. However after installation, it should successfully send emails to external users.

No comments:

Post a Comment