Normally if there’s a need for a no-reply email message in Power Automate Flows, the Mail connector is used.
But when using Mail connector the sender display name can’t be changed. It will always be “Microsoft Power Apps and Power Automate”.
However, if the message needs to be sent to internal users within your tenant only, an alternative approach using SharePoint Rest API and the ‘Send an HTTP to SharePoint’ action can be used to use a custom sender name.
In this post I’ll use a simple example of a Power Automate Flow that triggers an email message when an item is created or modified in a SharePoint list, to demonstrate how to do it:
SharePoint list structure
The sample Flow will be triggered from a SharePoint list with the following columns:
And following settings for ‘Body’ Multiline Text Field (so we get the content with HTML formatted text for the email body):
Create a new Flow being triggered when an item is created or modified in this list:
As a good practice, I recommend using the ‘Get item’ action after the trigger and reference any information for the list item from this action where it has to be used in the flow, instead of referencing data from the Flow trigger. This enables you to change the Flow trigger in the future if needed or reused in a modified copy of the Flow without any issues.
Escaping problematic characters from e-mail subject and body
To manage special characters that can raise issues when building the JSON content to be posted to SharePoint, let’s associate the ‘Title’ (which will be used as subject) and ‘Body’ content into variables using some replacements in the formula:
The JSON body will be built using single quotes to simplify, so we need to properly escape it in the content and also escape the backslash character to avoid issues if they appear in the subject or body content.
The formula to initialize the ‘Subject’ variable escapes backslash/single quotation mark by replacing backslash with double backslash and replacing the quotation mark by right single quotation mark value:
The formula to initialize the ‘Body’ variable replaces backslash and single quotation mark to HTML coded equivalent, as the e-mail body will be sent in HTML:
SharePoint HTTP: Sending the e-mail message
The last action which will do the trick is the ‘Send an HTTP request to SharePoint’ to make a call using the POST method the SendEmail ( _api/SP.Utilities.Utility.SendEmail) endpoint:
Post Headers to be sent:
- Content-Type: application/json;odata=nometadata
- Accept: application/json;odata=nometadata
Post Body (if your Flow has the exact same names as the example you can copy the structure below and paste in the editor):
- From: a valid user e-mail address from any user with a mailbox in your tenant to be used as sender name. It will be used only to change the name of the sender in the message.
- To: an array of destination e-mails from valid users in your tenant.
- Subject: String to be used as the subject for the e-mail message
- Body: content in HTML format to be the e-mail body
The sender has to be an e-mail address from an internal user in your tenant, so SharePoint will get its display name and add to the message.
Note: If you don’t specify the ‘From’ property in the JSON body, the email message will be sent using the site title as sender name.
After saving the Flow, just add a new item to the source list. In the example below, ‘Luke Skywalker’ is an existing user in my development tenant.
When the Flow is executed, the user will get an HTML formatted email coming from firstname.lastname@example.org, but with the ‘From’ user name as sender display name (Luke Skywalker):
When using this approach bear in mind some limitations:
- It works only for internal users in your tenant, with valid mailboxes (sender and destination addresses)
- It’s not possible to add attachments to the email message
Use this trick wisely, this is useful in workflow scenarios but be careful to not try sending an e-mail with someone’s name on it when you should not. The idea here is mainly for the message not to appear as coming from a ‘Service User’ in a workflow, but not to use this with bad intentions.