2 Ways to Attach Files to an Email in Power Automate

Do you need to attach a file to an email you send from Power Automate?

Suppose you want to email a report or document to someone as part of a flow. Power Automate can help you automate sending email attachments so that you don’t have to do it manually each time. You can create a flow that attaches files from OneDrive or SharePoint.

Unfortunately, it’s not exactly obvious how to attach files to an email sent from Power Automate.

This post is going to show you how to attach single and multiple files to your email in your flow.

Attach a Single File to an Email

If you only need to attach one file to your emails, then the setup is much more simple.

You can first get the content from your file in SharePoint and then attach it to the email.

  1. Add the Get file content action from the SharePoint connector to your flow.
  2. Select the SharePoint Site Address where your file is located from the dropdown.
  3. Select the File Identifier using the folder icon to navigate to the file.

Now the flow is ready to email this as an attachment.

  1. Add the Send an email (V2) action from the Outlook 365 connector to your flow.
  2. Fill in the required To, Subject, and Body fields.
  3. Click on the Show advanced options link at the bottom of the action.

This will reveal the advanced option for the email action which includes the Attachment Name and Attachment Content fields.

  1. Add the name of the file to the Attachments Name field as a text value. Make sure to include the file extension such as .pptx appended to the end of the name.
  2. Add the File Content dynamic content from the Get file content action into the Attachment Content field.

If you want to attach a second file, you can press the Add new item button and this will create another pair of Name and Content fields that you can populate.

This will require that you use another Get file content action if you want another file added.

That it! You now have an email with an attachment in your flow.

Attach Multiple Files to an Email

The previous approach is ok when you want to attach one of two files and the files will remain static for each run of the flow.

But there is a more dynamic way to attach multiple files based on a SharePoint folder.

This allows you to attach all the files from a given folder to your flow.

First, you will need to list all the files in your chosen folder.

  1. Add the List folder action from the SharePoint connector.
  2. Select the SharePoint Site Address where your file is located from the dropdown.
  3. Select the File Identifier using the folder icon to navigate to the folder.

Now you need to create an array variable that will hold the file name and contents for each file in the folder. This is what the email action will use to attach all the files.

  1. Add the Initialise variable action to your flow.
  2. Give the variable a Name such as arrAttachments.
  3. Select the Array option as the Type.
  4. Leave the Value blank. You want to start with an empty array as you will be later adding all the file names and content.

Now you can get the content for each of the files in the folder.

  1. Add the Get file content using path action from the SharePoint connector to your flow.
  2. Select the SharePoint Site Address where your file is located from the dropdown.
  3. Add the Path dynamic content from the List folder action to the File Path field.

As soon as you add the Path dynamic content to the File Path field, Power Automate will add an Apply to each action to your flow. This will allow the flow to loop through each file in the folder.

  1. Add an Append to array variable action inside the Apply to each action right after the Get file content using path action.
  2. Select the arrAttachments variable created in step 5.
{
  "Name": "@{items('Apply_to_each')?['DisplayName']}",
  "ContentBytes": @{body('Get_file_content_using_path')}
}
  1. Add the above into the Value area. This will create the required array item of the file contents for each file in the folder.

The Name is the DisplayName dynamic content from the List folder action and the ContentBytes is the File Content dynamic content from the Get file content using path action.

Now you can add this array to the email.

  1. Add the Send an email (V2) action from the Outlook 365 connector to your flow. Add this outside of the Apply to each action so you only send one email!
  2. Fill in the required To, Subject, and Body fields.
  3. Click on the Show advanced options link at the bottom of the action.

Instead of entering each attachment individually as previously done, you can enter the attachments as an array!

  1. Click on the Switch to input the entire array button in the attachment section’s top right area.

This will transform the Name and Content inputs into a single input area for Attachments.

  1. Add the arrAttachment array dynamic content to the Attachments input.

That’s it. The flow will now list all the files in the folder and add them as attachments to an email.

Conclusions

Adding attachments to emails is a very common task, so this is something you will no doubt need to do in Power Automate at some point.

While adding a single attachment is fairly straightforward, it’s still not obvious how to do it.

This gets even more complicated when you want to add multiple attachments.

Hopefully this tutorial will help you out! Let me know in the comments below!

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Related Articles

Comments

13 Comments

  1. Fábio

    Thanks for this!
    For me it says The response is not in a JSON format. on List folder step, for multiple files.
    I cannot figure it why.
    Could you help?

  2. Mohammad

    Hi John,
    Good afternoon,
    I’m getting error that says No input parameters provided. Please provide required input parameters ‘To’, ‘Subject’ and ‘Body’.
    clientRequestId: 17835f35-4a58-4303-9a08-8e263df7c389

    But I filled all the form,

    Can you assist me with it?

    Thanks in advance.

    • John MacDougall

      I would start by checking what was returned in the flow for those fields.

      • Mohammad

        Hi John,
        Thanks for your reply,

        My concern is sending attachments when a file is created on SharePoint, all is working the process is looks nice and I have all green marks, but when a file is created, it has an issue with the attachment,

        Is there any gold point that can assist me, every week I’m sending 40 emails to different parties, which is time-consuming. if I can make it, I saved a lot of time.

        Have a nice time,
        Stay safe
        Mohammad

        • John MacDougall

          What is the issue with the attachment?

          Another option would be to share the file as a link in the email.

  3. Amanda McArdle

    Thanks for this article. It was quite helpful. All is working except the PDF attachment won’t open. The error states the file couldn’t be opened because it’s either not a supported file type or it was sent as an attachment that wasn’t decoded correctly. When I’ve run up against this with flows where the new file was the trigger, I had to select, from dynamic content, File name with extension ffor the name and body for the content. Any suggestions to resolve?

  4. Joe Wade

    Thanks for the steps. When using the attach multiple files to an email, the system sends a number of emails.
    Say I have 5 files to attach in the folder, there will be
    1 email with 1 file
    1 email with 2 files
    1 email with 3 files
    1 email with 4 files
    1 email with 5 files.
    How do you solve this so that is is only 1 email with 5 files sent.

    • John MacDougall

      This sounds like your email action is inside the Apply to each action. It will need to be outside.

  5. Aaron Horton

    This is really useful, but I’ve run into a bit of an issue. Everthing works fine with PDF files, but MS Office files seem to have thier content changed (the ‘source’ files are ok in the SP library they are stored in) so that when you open them up in Notepad, the Office files only contain info like ‘File not found\r\nclientRequestId:….’ instead of ‘normal’ data. It even works with PDF files with multiple attachments that include Office files. The PDFs are fine, the Office files are changed. Any thoughts as to why or how this could be remedied please?

  6. Rebecca, NZ

    Thank you for your clear instructions – worked a treat for me!

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!