Draft mail message for a selected item

I got an interesting question on the Power Users forum a while back about e-mail templates. In this article I am creating a flow which will post a draft Outlook 365 email with dynamic content of a selected SharePoint list item.

Original request

I want to start an email form a SharePoint list item, that is populated with details from the selected item, but the author of the email can complete the email, address the email and then send it when finished.

Start an email form a SharePoint list item

The approach

– Create a button in a SharePoint list which will trigger the flow
– Create a flow which asks for an e-mail input and use an http with a Graph API create message request (this will create a draft outlook message).

This action however does require a App registration in Azure AD and the correct permissions (Mail.ReadWrite):
Using Flow with Graph API by Lee Ford
User Post Messages

The setup

1. Add a for a selected item trigger action. Add an Email Input

2. Add an HTTP action. Use the following URI field value. Notice the x-ms-user-id in the URI. This will make sure that the draft is created in the mailbox of the person who is triggering the flow.

3. For the body I am using this example. However, you can add other dynamic values to it if you want. The email of the input is used for the To: field of the draft e-mail. Below is the json I used in my example.

URI
https://graph.microsoft.com/v1.0/users/@{triggerOutputs()['headers']['x-ms-user-id']}/messages

Body
{
    "subject":"E-mail template flow",
    "importance":"Low",
    "body":{
        "contentType":"HTML",
        "content":"They were <b>awesome</b>!"
    },
    "toRecipients":[
        {
            "emailAddress":{
                "address":"@{triggerBody()['email']}"
            }
        }
    ]
}

4. Add the button (formatting) to your SharePoint List. In this example my column is called SendMail. Don’t forget to add id of your flow. Below is the json I used in my example.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "button",
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "{\"id\":\"yourflowid\", \"headerText\":\"Example E-mail Template\",\"runFlowButtonText\":\"Send E-mail\"}"
  },
  "attributes": {
    "class": "ms-fontColor-themePrimary ms-fontColor-themeDark--hover",
    "title": "Launch Flow"
  },
  "style": {
    "border": "none",
    "background-color": "transparent",
    "cursor": "pointer"
  },
  "children": [
    {
      "elmType": "span",
      "attributes": {
        "iconName": "Mail"
      }
    }
  ]
}

Testing

1. Go the SharePoint list and click the SendMail button for an individual list item. This will trigger the flow from the SendMail button and show a input box where you can enter a recipient e-mail address. Click Send E-Mail.

2. A draft e-mail will be created in the drafts folder of the user who triggered the flow.

Happy testing!

This blog is part of SharePoint Week. For more great content, click here

About the Author:

My name is Dennis. I am Dutch and I live and work in the UK as an IT consultant. Currently I work a lot with SharePoint online, Microsoft Teams and all the other products of the Office 365 platform. I also like my share of Dynamics 365 and Azure. I try to blog about everything I come across in my daily job. All the content in my blogs are my personal views and experiences.

Reference:

Dennis. (2021). Draft mail message for a selected item. Available at: https://www.expiscornovus.com/2021/04/14/draft-mail-message-for-a-selected-item/ [Accessed: 13th September 2021].

Share this on...

Rate this Post:

Share:

Topics:

General

Tags: