Musings and Solutions for SharePoint, O365, and Azure

2013 Workflow

Send Email through Visual Studio Workflow in SharePoint 2013

August 25, 2015

Send Email through Visual Studio Workflow in SharePoint 2013

EmailActionWhen building a custom SharePoint 2013 Workflow using Visual Studio I ran into a very odd problem trying to send a notification email to a group of users using the Email action (specifically Microsoft.SharePoint.DesignTime.Activities.Email). 

I could send email from a SharePoint 2013 workflow created using SharePoint Designer, but could not do the same from my custom workflow created in Visual Studio without the workflow throwing an error.  I’m not even going to post the error because as it turns out it’s a generic error message that could show up for any number of reasons and has little to nothing to do with the problem which was partially why it took so long to solve.

My colleague Bob German (Blog ~ twitter: @Bob1German ) gave me an assist debugging and testing out the issue… By using Fiddler, set up to run on my SharePoint server under the Workflow Manager App Pool account, I was able to see why the call works from a SharePoint Designer workflow but not my custom VS2013 workflow. What I found was that when the call was made from the SharePoint Designer workflow, the “To” address was in the form of the users login name and not the email address.  So even though the documentation states that the “To” property “Gets or sets the user names or email addresses that represent the recipients of the email message.”, that is apparently not entirely the case.  By tweaking the value I pulled from the LookupSPUser activity from Email to LoginName and adding that value to the recipient’s collection, everything worked beautifully.


As an aside, from this same Fiddler investigation, I also found that the SharePoint Designer email action formats the body as an HTML message and if you want to use that you can by embedding your body in between the following tags:

<HTML><HEAD> <META name=GENERATOR content=\"MSHTML 11.00.9600.17924\"></HEAD><BODY><FONT face=\"Segoe UI\">

<Email Body Here>


    Julie has been building software on primarily the Microsoft platform for over 20 years. With a degree in Electrical Engineering specializing in microprocessor system design from Worcester Polytechnic Institute she came at software initially from a very low level but quickly realized a love and aptitude for developing rich user experiences and solutions. She worked her way up through internal IT ranks reaching a Director of IT position before realizing more impact could be made in consulting and really focused in on the SharePoint platform in 2007. Since then her focus has been on the SharePoint platform, Office 365, Azure, and client side development. She's the co-author of the Widget Wrangler JavaScript library and continues to try and help innovate SharePoint and Office 365 solutions for her clients. She is a 2017 recipient of the Microsoft MVP award for Office Servers and Services.

    1. Super! Thank you for posting the link to that as it helps explain all the intricacies I glossed over.

    2. This is great ! This just answered the problem I tried to tackle yesterday for hours and although I haven't tried this yet, I believe I could get my emails sent without having to write some custom email activity into my client's SharePoint. Thanks a bunch :)


      I am developing Sp 2013 workflow using Visual Studio 2013. I have used OOTB "Email" activity but when I start build, it takes almost 30 mins. to build & if I remove the "Email" activity it builds within 5 mins. what's wrong with "Email" activity or the contents ? I have followed your suggestion. Any guess?

    4. Unfortunately I really have no idea what could be wrong. What I might suggest though is to do some investigation of the output window during your build. I would suspect it may give you some clues.


        Thank you. I have already observed the output window but nothing found. It simply says.. build started... and then after long time it do the deployment process.

    Leave a comment

    Leave a Reply

    %d bloggers like this: