One of the common requirements is to send emails with multiple attachments from a content source like SharePoint. In this article, we will see how we can set up a collection to gather all the required attachments and then add it to the mail while sending it out to the receiver.
The summary of the steps used in the implementation would be:
- Initialize the power automate based on the Item creation trigger on a SharePoint List
- Use the Get Attachments Action to get all the attachments associated with that specific list item
- Initialize an array variable to hold the attachments collection
- Use the Get Attachment Content action in a loop to get the content of each attachment and append it to the previously initialized array variable
- Add the array of attachments to the Send Email Action
Let’s first add the trigger condition for the Power Automate which will be the “When an item is created” and associate it to the specific list where we want to run the flow.
Now let’s call the Get Attachments Action to extract all the attachments of the list item that was created recently. We will also initialize an array to hold the attachments collection.
Now let’s add an apply to each loop to loop through the body of the “Get Attachments” action and get the File Content of each of the attachments.
The values of ID and File Identifier used in the action Get Individual Attachment content is as follows:
- ID: ID obtained from the Dynamic content output of “When an item is created” trigger
- File Identifier: Id output from the “Get Attachments from the list item” action
We will also start building the attachment collection array in this apply to each loop by building the attachment item which contains 2 properties:
- Name: Display Name is retrieved from the out put of the Get Attachments from the list action
- Content Bytes: Body retrieved from the Get Individual attachment content action
At the end of the loop, we will have the array which contains all the attachments from the list items. Now we will use the Send mail action to add this array as an attribute to the “Attachments” parameter in the action as below:
Thus, the complete flow would like:
To test the flow, let’s create an item in the SharePoint list and add 5 attachments to it. On item creation, the flow will be executed, and the flow run succeeds by attaching multiple attachments to the mail.
We have also received the mail with multiple attachments:
Thus, we saw how to combine multiple attachments into an array collection and use it for sending mail to a receiver using Power Automate and SharePoint.