Sending email with multiple attachments from Power Automate cloud flow

August 14, 2023
Daria Rakkad

Situation

Most RPA processes perform day-to-day, already established business processes. Inevitably, an enormous number of these processes are used to send e-mails - both on confirmation of the completed robot work, as well as on generating reports that are mostly sent through emails. ​

In these situations, Power Automate Desktop makes it easy for us to send emails with built-in actions. Unfortunately, undisruptive work with Outlook (which is a built-in action in PAD) is not always accessible.​

Consequently, working with files is always not easy as it seems.​

In many situations an email application will not be the safest choice. Due to this, the best option is to send emails via cloud.​

Following steps will present how you can easily send an email with more attachments through the cloud application.​

Step 1 - initialization:

Initialize variables we’ll use later:​

           'Attachments Object' variable used for making attachment object containing name and content bytes.

           'Emails Array' variable (later used for storing every object (attachment) inside).

Step 2 - retrieving files:

1. List files in folder (OneDrive)

        You can manually choose folder from OneDrive connected to this account.​

2. Apply to each

        For each file take 'File Name' and 'Content Byte' for making 'Attachment Object'.

3. Get file content – uses id from each file to get content bytes

          >> items(‘Apply_to_each_-_get_files’)?[‘id’] <<

4. Set variable 'Attachment Object' by populating it with JSON format:​
              {

                                  “Name”: >>items(‘Apply_to_each _-_get_files’)?[‘Name]<<,​

                                  “ContentBytes”: >>body(‘Get_file_content’)<<​

               }

5. Append to array variable – appends objects to 'Emails Array'.

Step 3 - sending email:

1. Send an email (V2) 

        Show advanced options.

        In Attachments section click on switch to input entire array option on the right.

        Add array to attachments.

Step 4 - deleting files (Optional):

Additionally, we'll delete all files from our temporary folder on OneDrive.

1. List files in folder for deleting – choose folder from OneDrive

2. Apply to each - deleting files

3. Get files metadata using path

        In this action you can take dynamic file path, using name

        >>items(‘Apply_to_each_-_delete_files’)?[‘Name’]<<

4. Delete file – takes id output from previous step

Cloud flow representation:

At the end, our flow looks like this.