If you are working on SharePoint, you know it is easy to send an email to SharePoint groups through SPD/Nintex workflows, because these are the apps related to SharePoint which know the SharePoint context. On the other hand, MS Flow is a separate Office 365 app and independent of SharePoint but this also helps in automating the workflows. However, here comes the issue. MS Flow can recognize the O365 users but there is no straightforward way to get the SharePoint group users from the dynamic data.
There are different ways to achieve this solution. In one of the articles I read online, the user did a REST call to get all the group users from the group and had to use foreach loop to get all the users' email ids in a variable. Then, he used that variable to send an email. But I found the following way very simple and time saving.
In short, we are going to send an email via SharePoint Rest API by hitting "/_api/SP.Utilities.Utility.SendEmail" pointing to send the email to SharePoint group.
Steps
- In your flow, add this step – Send an HTTP request to SharePoint.
- Fill in the following details.
- In the Site Address, select your SharePoint site URL.
- Select the method as POST.
- In URI, add this endpoint : /_api/SP.Utilities.Utility.SendEmail
- In headers, accept application/json;odata=verbose
content-type: application/json;odata=verbose
- In Body, write the following code.
- {
- 'properties': {
- '__metadata': {
- 'type': 'SP.Utilities.EmailProperties'
- },
-
- 'To': {
- 'results': ['test group ']
- },
- 'Body': '<p>This is a test email</p>',
- 'Subject': 'Test email from MS Flow'
- }
- Please check the screenshot to verify.
- Now, run your workflow. I created a test group in which two users were present. Below is the email that I have received from [email protected]. This is another advantage using SP utilities to send email. If you use default send email action, the MS Flow runs on the context of the user who created the flow and sends email from his email id. So, going with SP utilities is a great advantage if you wanted to send system-generated type of emails.