🖇️How to Read SharePoint List Item Attachments and Send Them via Email Using Power Automate

In this article, I will walk you through the process of reading a SharePoint List item and its associated attachments, followed by the step-by-step instructions on how to email those attachments using the Send Mail action in Power Automate. By the end of this post, you will have gained the knowledge and skills necessary to effectively read SharePoint List items and send their attachments via email using Power Automate.

What does the flow do?

The flow uses a manual trigger and requests the user to enter a SharePoint List item ID. The file attachments associated with the item ID are then emailed to the user.

The demo SharePoint List I’m using is called Contracts Library as shown below. The list item ID that the user wants to enter when running the flow will be 47.

This is the demo SharePoint List . This is the item ID that the user will enter is 47 when running the flow.
This is the demo SharePoint List. The item ID that the user wants to enter when the flow runs will be 47.

List item 47 has three file attachments:

The item has three file attachments.
The item has three file attachments:

When the flow is run the user is requested to enter a List item ID, for example 47:

When the flow is run the user is requested to enter a List item ID, for example 47
When the flow is run the user is requested to enter a List item ID.

The flow executes and an email containing three file attachments is sent to the user:

An email containing the three file attachments has received.
An email containing the three file attachments has been received.

Finally, open each file attachment to ensure that the files are not corrupt and are valid documents:

Open each file attachment to ensure that the files are not corrupt and are valid documents.
Open each file attachment to ensure that the files are not corrupt and are valid documents

Here is the flow that we will build

Image of the flow we will build
This is the flow that we will build

How to Display the ID column

1. Click the Add Column option, then select Show or Hide Columns:

2. Tick the ID column then click Apply. Use the arrows ∧ ∨ to change the ordering of the columns:

Tick the ID column then click Apply.

Building the flow

1. For this demo we’ll start by creating an Instant cloud flow:

Select Instant Cloud Flow
Select Instant Cloud Flow

2. The flow will use a manual trigger. Give your flow a name then select the trigger as Manually trigger a flow (1):

Select Manually trigger a flow
Select Manually trigger a flow
The flow is triggered with a manual trigger action
The flow is triggered with a manual trigger action

3. We want to request that the user enters a SharePoint List item ID number when the flow is run. Open the Manually trigger a flow action and click Add an Input:

Select Add an input to the Manual trigger.
Select Add an input

Click Number:

We want to request that the user enters a SharePoint List Item ID number when the flow is run. Select Number for the manual trigger.
Select Number.
A number input has been added to the  manual trigger.
A number input has been added to the manual trigger.

Next, change the name of the number field. You can also update the help text to something more meaningful:

Change the name of the number field to List Item ID.
Adding a number input to the manual trigger.
Changing the name of the number field and updating the help text to something more meaningful.
Changing the name of the number field and updating the help text to something more meaningful.

4. Add a Get attachments action (2). Select the SharePoint site and List. For the Id select List Item ID from Dynamic content:

Adding the Get attachments action (2). Select the SharePoint site and List. For the Id select List Item ID from Dynamic content.
Get attachments action
For the Get Attachments Id select List Item ID from Dynamic content
For the Id select List Item ID from Dynamic content

5. Add an Initialize variable action (3) of type array:

Initialize variable action for the attachments array
Initialize variable action for the attachments array

We will store the content of each attachment in the array variable varAttachmentOutlook.

6. Add an Apply to each loop (4) and set the Get attachments Body (5) as the output from previous step as shown below:

Add an Apply to each loop (4) and set the Get attachments Body (5) as the output from previous step as shown below
Add an Apply to each loop (4) and set the Get attachments Body (5)

The Apply to each loop will get the content of each attachment and store the attachment content and attachment name in the array variable varAttachmentOutlook.

7. Add a Get attachment content (6) action:

Add a Get attachment content (6) action
Add a Get attachment content (6) action

8. For the Id select the List Item ID, and for the File Identifier select the Id (File Identifier) from Get attachments:

For the Id select the List Item ID, and for the File Identifier select the Id (File Identifier) from Get attachments
For the Id select the List Item ID, and for the File Identifier select the Id (File Identifier) from Get attachments

9. Next add an Append to Array variable (7) action:

Add an Append to Array variable
Add an Append to Array variable

The array variable will store the attachment name (Display Name) and attachment content in a JSON object. Enter the following as shown in the steps below:

Add an append to array action. The array variable will store the attachment name (Display Name) and attachment content in a JSON object.
The array variable will store the attachment name (Display Name) and attachment content in a JSON object.

Pay attention to the brackets, quotation, colon and comma characters:

The array variable will store the attachment name (Display Name) and attachment content in a JSON object. Pay attention to the brackets, quotation, colon and comma characters in the JSON code.
Pay attention to the brackets, quotation, colon and comma characters:

Select the Attachment Content and Display Name from dynamic content as shown below:

Select the Attachment Content and Display Name from dynamic content
Select the Attachment Content and Display Name from dynamic content

10. The final action is the send mail action. Add a Send an email (V2) action (8):

Add a Send an email (V2) action
Add a Send an email (V2) action

11. Select Show advanced options:

In the Send an email (V2) action select Show advanced options.

12. Next switch the attachments mode to input entire array, then add the attachment array from Dynamic content as shown below:

Send an email action containing the attachment array.
Switch the attachments mode to input entire array, then add the attachment array from Dynamic content

Trouble shooting

If you find that attachments do not open, see Short Notes: The format of File Attachment Arrays for Approvals and Outlook Emails

If you find that in some instances the above does not work, i.e., the file attachment won’t open, I have included an alternative format for the attachments array.

An alternative format for the File attachment arrays for Outlook email.

You can copy-and-paste the following code into the “Append to array variable” action:

{
  "name": "@{items('Apply_to_each')?['DisplayName']}",
  "contentBytes": {
    "$content-type": "@{body('Get_attachment_content')?['$content-type']}",
    "$content": "@{body('Get_attachment_content')?['$content']}"
  }
}

So, why do different array format work for some people but generate corrupt attachments for others?


3 thoughts on “🖇️How to Read SharePoint List Item Attachments and Send Them via Email Using Power Automate

Add yours

  1. Thank you so much for this very detailed tutorial! Its not easy to find such detailed, step by step instructions for Sharepoint beginners like me. Although I wasn’t successful in getting my flow to work, I wanted to thank you for being so thorough.

  2. Hello, many thanks for your detailed description of the flow. I would like to create the flow, but in my additional /separate created approval workflow I used the step “Grant access to an item or folder” and “Stop sharing item / elements or folder”. Do you know if your flow will work in combination with my used steps? Thanks in advance! Best regards Andreas

    1. Hi Xanoxs,

      The flow will work with “Grant access to an item or a folder” and “Stop sharing an item or a file”. In that case you can include a link to the item in the approval work flow, and you wont need to send the attachments.

      But if you do want to send the list item file attachments in the approval action, then the format of the array will need to change slightly. Replace “ContentBytes” key with “content” in the Append to array variable action:

      {
      “name”:
      “content”:
      }

      But note that file attachments don’t appear in Teams approvals action that the recipient receives. One day Microsoft will fix this.

      Please see:
      (1) Best Practices for Formatting File Attachment Arrays in Approvals, Outlook Emails, OneDrive, and SharePoint
      https://elliskarim.com/2022/08/15/short-notes-the-format-of-file-attachment-arrays-for-approvals-and-outlook-emails/

      and

      (2) How to Send Microsoft Forms File Uploads to an Approval Workflow Using Power Automate
      https://elliskarim.com/2022/01/17/how-to-send-microsoft-forms-file-uploads-to-an-approval-workflow-using-power-automate/

      Ellis

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 )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Website Built with WordPress.com.

Up ↑

%d bloggers like this: