Dynamically create a list of e-mail attachments with Microsoft Flow : use Base64()

A few days ago I wanted to solve the following issue : we have a SharePoint document libraries containing a bunch of documents. And I needed to create a flow that read these documents and send them automatically by e-mail.

Si I did create a flow with the Send an e-mail action. One of the new option of this action is to be able to pass an array of attachments. By default the attachments are statically linked to the action unless you click the small icon next to the Attachments field:


This allows you to pass an array of attachments :


Now how can you define an array ? you can define an array variable, but before doing this we need to proceed to an experimentation :

Define a Compose before the send an en e-mail action. In the Compose add an array of object with a “Name” and a “ContentBytes” property , and pass this compose output to the send e-mail activity as illustrated below :


Now run your flow and you will see that it fails !


The reason is quite simple : you just have to encode you content with base64(), so let’s fix this.

Update the compose activity as described below:


Test the flow again and it works ! Check your e-mail, you should have received the mail with the attachment.

Now let’s apply this knowledge to an array & a SharePoint document library.


In your flow, let’s define a variable of type Array and name it myfiles:


Add a (SharePoint) Get files action to fetch the documents from the SharePoint document library :


Add an Apply to each action in the loop


After the Apply to each pass your variable to the send an e-mail action:


Your flow should look like this:


Test your flow and check your e-mails.


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