Send Email using SharePoint and MS Flow without Exchange

In this post I will (concisely :-) describe how to send a mail to a SharePoint user from Microsoft Flow in case the standard MS Flow send mail action doesn't work for you. This can happen if you don't use Exchange Online yet. Not a very normal case probably, but hey, maybe it'll help someone.
This also works for external accounts.

First you need to add the users you want to send mail to in a user group on a SharePoint site. This is required as the webservice we'll be using gets the user account info from a hidden list on the site that should include the user and his or her email address. So add the account to the site. The user doesnt actually need any permissions on the site, but the SharePoint site needs to 'know' the user.

Now before we can create the Microsoft Flow, you'll need to setup a SharePoint App on the site that we'll use the credentials of to send the email from Flow. Because we're going to call a SharePoint API from outside SharePoint we need a valid access token to be able to do so.

The method to get a valid token in a Flow described in an older post of mine: Call any SharePoint REST API from Microsoft Flow. It is based on the article Access SharePoint Online using Postman that clearly explains how to register an App in SharePoint to get a client id and client secret.

So see those two articles on how to get the token. You will need to call a specific URL with the client id and client secret passed to it in order to get an access token back. If you follow the previous post you will end up with a Compose action that contains the token string.

The final action is a HTTP Post to:
https://yourtenant.sharepoint.com/sites/siteyouregisteredyourapp/_api/SP.Utilities.Utility.SendEmail

with headers:
Accept: application/json;odata=verbose content-type: application/json;odata=verbose
Authorization: Bearer <add the output of the compose action that holds the token here>

and the body:
{ "properties": { "__metadata": { "type": "SP.Utilities.EmailProperties" }, "From": "jurgen.wiersema@domain.nl", "To": { "results": ["jurgen.wiersema1@domain.nl"] }, "Body": "Boe!", "Subject": "Test flow email" } }

In order to mail external users, you need to add the User Principal Name to the To property in the JSON, e.g. "i:0#.f|membership|jurgen.wiersema_gmail.com#ext#@jwiersem.onmicrosoft.com". This account needs to have the external mail address set in its profile of course.

Additional considerations:
- The user needs to have been added to the SharePoint Site you call the SendEmail webservice on. You can automate this within MS Flow by calling a different REST API method, which is the EnsureUser method. - If you want to re-use this Email users Flow functionality, then you can build the Flow as HTTP triggered. If you pass the JSON above into it, which you then use in the action to post to the webservice, then you can re-use this Flow in all your other Flows by using a HTTP Post action to the Re-usable Flow URL.

Mail from Flow 1 Get token HTTP call

Mail from Flow 2 Send Email through a REST call - 1

Mail from Flow 3 Send Email through a REST call - 2

Mail from Flow 4 Email received by external user

Show Comments