SharePoint Hosted Add-in: Send Email to SharePoint group using visual studio workflow

how to send email to SharePoint group using workflow?
SharePoint deveopment training course

This SharePoint tutorial explains, how we can send email to a SharePoint group in visual studio workflow in SharePoint Online through a SharePoint hosted add-in.

Before proceeding further make sure to visit the below article where it has been explained step by step how we can create a workflow using visual studio 2015/2017 as a SharePoint hosted add-in and how we can deploy the workflow to host web. Because we have to follow the same steps also.

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

SharePoint Hosted Add-in: Send Email to SharePoint group using visual studio workflow

Before going further for workflow, I have created a SharePoint group and I have added two users to the SharePoint group. Now in the workflow when I will send the email, the email should go to all the users presented inside the group. The SharePoint groups look like below:

Send Email to SharePoint group using visual studio workflow
Send Email to SharePoint group using visual studio workflow

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

sharepoint online workflow email activity
sharepoint online workflow email activity

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.

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

send email using visual studio workflow
send email using visual studio workflow

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 Activity.

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.

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

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

We can send an email to a SharePoint group. But If I will simply put the group name in To as a string like below, it will through me an error.

Email Workflow activity example
Email Workflow activity example

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

new System.Collections.ObjectModel.Collection() { "MyCustomSharePointGroup"}

The full email properties will look like below:

send email to sharepoint group in visual studio workflow in SharePoint online
send email to sharepoint group in visual studio workflow in SharePoint online

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”.

how to send email to SharePoint group using workflow?
how to send email to SharePoint group using workflow?

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]. Click on your App name and then click on Add a workflow.

send email using visual studio workflow sharepoint online
send email using visual studio workflow sharepoint online

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.

send email using visual studio workflow
send email using visual studio workflow

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. Click on the … -> Advanced -> Workflows like below:

sharepoint online workflow email activity
sharepoint online workflow email activity

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

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

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 activity.

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

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

send email to sharepoint group in visual studio workflow in SharePoint online
send email to sharepoint group in visual studio workflow in SharePoint online

You may like following SharePoint workflow tutorials:

Hope this SharePoint tutorial explains, how to send email to SharePoint group in visual studio 2015/2017 workflow in SharePoint hosted add in SharePoint online?

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →