SharePoint HTTP connector: Send a no-reply email from a specific sender name in a Flow

Normally if there’s a need for a no-reply email message in Power Automate Flows, the Mail connector is used.

mail

But when using Mail connector the sender display name can’t be changed. It will always be “Microsoft Power Apps and Power Automate”.

unsubscribe2

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:

Capture3

And following settings for ‘Body’ Multiline Text Field (so we get the content with HTML formatted text for the email body):

Capture4

Flow Trigger

Create a new Flow being triggered when an item is created or modified in this list:

start

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:

vars

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:

  • replace(replace(body(‘Get_item’)?[‘Title’],””,’’’),’\’,”)

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:

  • replace(replace(body(‘Get_item’)?[‘Body’],””,”’),’\’,’\’)

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:

http

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):

{
    ‘properties’: {
        ‘From’: ‘@{body(‘Get_item’)?[‘From’]?[‘Email’]}’,
        ‘To’:[‘@{triggerBody()?[‘To’]?[‘Email’]}’],
        ‘Body’: ‘@{variables(‘EmailBody’)}’,
        ‘Subject’: ‘@{variables(‘EmailSubject’)}’
    }
}
Explaining the post body:
  • 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.

Results

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.

Capture2

When the Flow is executed, the user will get an HTML formatted email coming from noreply@sharepointonline.com, but with the ‘From’ user name as sender display name (Luke Skywalker):

message2

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

Reference:

https://www.techmikael.com/2018/11/sending-e-mails-in-microsoft-flow-using.html

2 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s