Create a draft Email in Outlook

email blocks on gray surface

Learn how easy it is to create a draft email in your Outlook Draft folder using Power Automate. Rather than send the email direct from Power Automate, let me show you a simple way to create a draft email. You can review, edit and send this email directly from your Outlook Mailbox. As well as a video to demonstrate how this is possible, I will further extend the concept below and show you how you can include attachments as part of your draft email.

Click here to read up on the Graph API we use to perform this PowerAutomate Flow.

Using the above documentation and the Graph Send an HTTP Request Action, we can create a draft email in one simple action. The content can include dynamic data including title, to, subject, body and of course attachments.

Graph API Draft Email

I haven’t included any copy / paste samples as Microsoft do a good job of this in their documentation. However, where it’s not so good, is an example that includes attachments.

Adding an attachment (from SharePoint)

In order to add attachments to your draft email, you need to contruct an array of attachment(s) objects that are made up as follows:

{
  "@odata.type": "#microsoft.graph.fileAttachment",
  "name": "@{items('Apply_to_each')?['{FilenameWithExtension}']}",
  "contentBytes": @{body('Get_file_content')?['$content']}
}

Note, that you must escape the @ in the attachment object by including two @@ or you will get an error when trying to save the flow.

In my scenario, I am using get files (properties only) action to get a list of files from SharePoint, you could of course filter this or make your file attachment(s) fixed by using get file content action. I use an apply to each to get each file(s) and add them to an object in a compose called Attachment.

Creating the array of attachments for the draft email

To create our object we must include the file name (which can be dynamic content) but also the contentBytes, this is built using an expression body(‘Get_file_content’)?[‘$content’] and must not include double quotes. Once we have our objects in the Attachment(s) compose action, we can bring them all together in an array using the expression outputs(‘Attachment’). This is a neat little trick to create an array, based on the data contained within the compose action(s) in an apply to each.

{
    "subject": "Files?",
    "importance": "Low",
    "body": {
        "contentType": "HTML",
        "content": "Quite a few files are attached!"
    },
    "toRecipients": [
        {
            "emailAddress": {
                "address": "damien@yourtenant.onmicrosoft.com"
            }
        }
    ],
    "Attachments": @{outputs('Attachment')}
}

The above HTTP body demonstrates how you might create a draft email with attachments.

Adding an Attachment (from OneDrive)

Sending file(s) from OneDrive is very simlar. You will need to construct the expression for the file content. The expression I have used for my excel file is outputs(‘Get_file_content’)?[‘body’]?[‘$content’].

Above, I am attaching a single file. Don’t forget about escaping the @ symbol. As this is a single file, we need to form an array by adding [ opening and closing ] square brackets (see below).

Adding the attachment array to the body of the email is exactly the same. You can add it by calling the expression outputs(‘Attachment’) or by using the dynamic content block.

The Drafts

All you have to do now, is have a look in your draft folder. Open up the draft, make any changes and hit send!

Looking to go a bit more complex?

If you are looking to create a draft email containing HTML, a link to a website, a mailto link or maybe a signature, take a look at the example flow below which can be downloaded from my git hub here!

using compose to create HTML components
A signature block and main body in HTML
Create a draft email using Graph API in Power Automate

And here is what your draft email created in Power Automate will look like:

Sample draft email generated using Graph API

Please let me know how you have used this in your own solutions.

Share