How to Send an Email With Attachment From SharePoint List using Power Automate?

Recently, I have been working on a Leave request application, which I need when a new leave request is added to the SharePoint list send an email to the requested with an attachment using Power Automate.

In this Power Automate tutorial, I will explain how to send an email with an attachment from a SharePoint list in Power Automate.

Send an Email With Attachment From SharePoint List using Power Automate

To do this, I created a SharePoint list using the below column and data types for this example.

Power Automate send email with attachment

Let’s follow the below steps:

1. Navigate to the Power Automate Home page, click + Create, select the Automated cloud flow, provide the flow name, choose the flow trigger (When an item is created), and click the Create button. Then, Provide the Site Address and List Name inside the trigger.

Power Automate send email with attachment from SharePoint

2. I will take the Initialize variable action to store the attachments. To do this, provide the below Parameters as it is:

  • Name: varAttchments
  • Type: Select Array from the drop-down

Here, I changed the action name Initialize variable to Initialize variable | var Attachments.

Power Automate send email with attachment from SharePoint list

3. Next, add the ‘Get attachments‘ action and provide the below parameters:

  • Site Address: Select a specific SharePoint site from drop-down.
  • List Name: Choose a particular list.
  • Id: Select Id from dynamic content under When an item is created.
Power Automate attach file to email

4. After that, take the Get attachment content action to retrieve the details from the attachment. Then, Provide the below parameters:

  • Site Address: Select a specific SharePoint site from drop-down.
  • List Name: Choose a particular list.
  • Id: Select Id from dynamic content under When an item is created.
  • File Identifier: Take Id from the dynamic content of Get attachments.

You can see that a For each loop will be added automatically, taking Body outputs from Get attachments.

Send email with attachment from SharePoint Power Automate

5. Then, add Append to array variable action inside the loop, and set the below details:

  • Name: Select the name from the drop-down.
  • Value: Insert the below given code.
{
  "name": "@{item()?['DisplayName']}",
  "contentBytes": {
    "$content-type": "@{body('Get_attachment_content')?['$content-type']}",
    "$content": "@{body('Get_attachment_content')?['$content']}"
  }
}
Power Automate send email with attachment when item is created

6. Finally, add Send an email(v2) action outside of the loop. Set the required parameters:

  • To: Select Employee Name Email from dynamic content under When an item is created.
  • Subject: Provide a subject line for a mail.
  • Body: Provide a detailed description of a mail.

Then, click Show all to display the advanced parameters.

  • Attachments: Add attachments variable from dynamic content.
How to add attachment in Power Automate email

Once the Flow is ready, we will move forward to run the Flow.

Run the Flow to Send an Email With an Attachment From the SharePoint List

Now, it’s time to save the flow. Click on Test -> Select Manually. At this step, add an item to the SharePoint list with an attachment.

Add attachment to email Power Automate

When the flow runs successfully, it will send an email notification to the provided user with an attachment, as shown in the screenshot below.

Power Automate add attachment to email from SharePoint list

This way, we can get attachments from the SharePoint list and send emails using Power Automate.

Action ‘Append_to_array_variable’ failed: Unable to process template language expressions in action Power Automate

After creating the above flow, I checked with various scenarios, and I found that the flow successfully ran when the attachment files like PDF, Excel, Word document, jpg, or PNG, but when I try with a text file, it gives me an error like below:

Action ‘Append_to_array_variable’ failed: Unable to process template language expressions in action ‘Append_to_array_variable’ inputs at line ‘0’ and column ‘0’: ‘The template language expression ‘body(‘Get_attachment_content)?[‘$content-type’]’ cannot be evaluated because property ‘$content-type’ cannot be selected. Property selection is not supported on values of type ‘String’. Please see https://aka.ms/logicexpressions for usage details.’

Action Append_to_array_variable failed Unable to process template language expressions in action Power Automate

[Solved] Action ‘Append_to_array_variable’ failed: Unable to process template language expressions in action Power Automate

To solve this error:

Open the Append to array variable action inside the loop, and set the below details:

  • Name: Select the name from the drop-down.
  • Value: Insert the below given code.
{
  "Name": "@{items('For_each')?['DisplayName']}",
  "ContentBytes": "@{body('Get_attachment_content')}"
}
How to Send an Email With Attachment From SharePoint List using Power Automate

After that, save the flow and now add the item to the sharepoint list with a text file attachment. Then, you can see the flow run successfully and see it in the email with a text file.

[Solved] Action 'Append_to_array_variable' failed Unable to process template language expressions in action Power Automate

Conclusion

I trust this Power Automate tutorial gave you an idea of how to send an email with an attachment from a SharePoint list.

Also, you may like:

  • Is there a way to use “Send an email notification (V3)” ? This would be preferable as the automated emails do not come from my email account.

  • Hi, So I have a reminder flow that loops through a list and gets the reminder date which then sends a mail. How do I send singular attachment from a single row in the list since I used a “get items” action rather than “get item”, “get items” tend to loop and fetch all attachments from the list and send in the emails that come. I’m trying to send an attachment per row and not all the attachments within all the lists.

  • For the folks seeing issues using the attachments in approval workflows, use the following while constructing the arrary

    {
    “content”: {
    “$content-type”: “@{body(‘Get_attachment_content’)[‘$content-type’]}”,
    “$content”: “@{body(‘Get_attachment_content’)[‘$content’]}”
    },
    “Name”: “@{items(‘Build_Attachment_array’)?[‘DisplayName’]}”
    }

    Reference: https://powerusers.microsoft.com/t5/Building-Flows/The-request-content-was-invalid-and-could-not-be-deserialized/td-p/737581

  • I used the same logic to attach documents from OneDrive, but instead of single email the emails being sent is directly proportional to the number of attachments. Can someone help me here?

  • >

    Build a High-Performance Project Management Site in SharePoint Online

    User registration Power Apps canvas app

    DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

    Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

    Power Platform Tutorial FREE PDF Download

    FREE Power Platform Tutorial PDF

    Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…