Microsoft Flow: attach a file from SharePoint to Email

Why?

Even though we always should ask: “Why do you want to email something from SharePoint” multiple times, there may be some valid scenarios where we want to achieve an automated mail with one or more documents attached.

What?

In a previous post (https://knowhere365.space/microsoft-flow-create-a-file-based-on-another-file-in-sharepoint/) the basic actions about getting file data and content were explained so please have a look there. This post will continue with info based on those actions.

How?

Looking at the actions in the post mentioned above we just have to add two steps:

1) Create “something” from the found template files that we can use in an email action. I will use an array variable varArrayDocuments and add it directly after the previous action:

An Append to array variable action is best because this can also be used in case we would want to send multiple attachments (will post about this in a separate blog post later ⏳). This action for email purposes needs the following code:

{
"Name":@{body('Get_file_metadata_-_FoundTemplate')?['Name']},
"ContentBytes":@{body('Get_file_content_-_FoundTemplate')['$content']}
}

If we would not add the $content to the code of the ContentBytes part and simply would use the output of the Get file content action, the Flow would fail and give a rather unsatisfying error:”No input parameters provided. Please provide required input parameters ‘To’, ‘Subject’ and ‘Body’.

2) Use that array in a Send an email action:

and the email will have an attachment:

It even works with the Send an email action (V2) which is currently still in Preview ✔

One thought on “Microsoft Flow: attach a file from SharePoint to Email

Leave a comment