SharePoint online Send email in visual studio 2015 workflow using Email Workflow Activitity

sharepoint 2013 visual studio workflow send email to group

Here we will discuss how we can send email in visual studio 2015 workflow in SharePoint online through a SharePoint hosted add-in. Before procede further make sure to visit the below article where I have explained step by step how we can create a workflow using visual studio 2015 as a SharePoint hosted add-in and how we can deploy the workflow to host web.

Step by step develop workflows using visual studio 2015 as an add in and deploy to host web in SharePoint online

SharePoint Online Develop SharePoint Hosted Add-in using Visual Studio 2015 Demo

As we all know to work with Add-in model with visual studio we need first a developer site for local debugging. If you are new to this, then you can check below articles:

How to create developer site in Office 365 SharePoint 2013 Online?

Once you follow the above article and create your first workflow, the workflow screen will be appear like below where as a developer you can add activities.



sharepoint 2013 workflow send email visual studio
sharepoint 2013 workflow send email visual studio

From the toolbox from the left side, I have added two “WriteToHistory” activities from SP-Utilities section like below. In those “WriteToHistory” activities I have put some message which will be written to our Workflow History List.

In side these two activities I have added one “Email” activities from SP-Utilities section from toolbox. The workflow now looks like below:

sharepoint 2013 visual studio workflow send email to group
sharepoint 2013 visual studio workflow send email to group

Here in the above screen you can see an error mark which is coming because we need to add the mandatory properties inside the Email Activitity.

Here if you will look at the properties, you can see there are few optional properties, as well as few Required properties are there. Apart from that Display Name is also there, which we can change.

SharePoint online Send email in visual studio 2015 workflow
SharePoint online Send email in visual studio 2015 workflow

Here properties like Subject, Body will take string parameter. But properties like To, CC, BCC will take Collection of Strings as parameter.

So If I will simply put in To as a string like below, it will through me an error.

SharePoint 2013 Send email in visual studio 2015 workflow
SharePoint 2013 Send email in visual studio 2015 workflow

To resolve this we need to convert the string to collection of strings. You can write like below:

new System.Collections.ObjectModel.Collection<string>() { “Bijay@OnlySharePoint2013.onmicrosoft.com”}

The full email properties will looks like below:

SharePoint 2016 Send email in visual studio 2015 workflow
SharePoint 2016 Send email in visual studio 2015 workflow

Here for future propose I have given Full Control Access in AppManifest.xml file.

Now right click on the Project -> click on Deploy.




Once it is deployed successfully. It will ask you to trust the App like below. Click on “Trust It”.

Email Workflow Activitity visual studio 2015
Email Workflow Activitity visual studio 2015

Once you trust it, the workflow or the app will be available in all lists and libraries. In my developer site I have a list name as MyTestList.

Now Open the list and then go to the Workflow Settings page. Here you can see two Apps: This List and [Your App Name]. Clcik on your App name and then click on Add a workflow.

Email Workflow Activitity sharepoint 2013 visual studio 2015
Email Workflow Activitity sharepoint 2013 visual studio 2015

Here in the Add a Workflow page, It will show you the workflow templates, since I have only one workflow it is showing one. Then give a name for the workflow, choose the Task List, History List and choose the Start Options for the workflow. Then click on OK.

Email Workflow Activitity sharepoint 2016 visual studio 2015
Email Workflow Activitity sharepoint 2016 visual studio 2015

Now go back to the list and add one item to the list. Since the workflow will trigger on item add, you can see the details of the workflow.

sharepoint 2013 workflow send email
sharepoint 2013 workflow send email

Click on the … -> Advanced -> Workflows like below:

In the details page, click on your App, then you will be able to see the completed apps like below:

Email Workflow Activitity sharepoint online visual studio 2015
Email Workflow Activitity sharepoint online visual studio 2015

Click on it to see the full details of the workflow. Check out the history list, it has added the messages which we wrote inside the WriteToHistory activitity.

sharepoint 2013 workflow send email when new item created
sharepoint 2013 workflow send email when new item created

Now if you will check the email, you can see the messages like below:

send email activity sharepoint workflow
send email activity sharepoint workflow

Hope this article will be helpful.


About Bijay Kumar

I am Bijay from Odisha, India. Currently working with a reputed organization in Bangalore. I am Microsoft Office Servers and Services (SharePoint) MVP (4 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.

View all posts by Bijay Kumar →