My Digital Garden

Power Automate - attach files from SharePoint to email

Power Automate - attach files from SharePoint to email

If you have several files from SharePoint to send as attachments o na single email, this pattern shows how to correctly attach them so that he files will be readable at the receiving end.

Process

Overview

  • find the files in SharePoint
  • iterate over the files, reading details and content into a Power Automate array variable
  • use the array variable to attach all the files

Detail

Finding the files and iterating over them to retrieve content is documented in Power Automate - Read files from SharePoint directory.

The use of an array to collect attachments consists of the following operations:

  • initialise an array variable

  • In each iteration of the loop where you read content, append content to the array variable (note this means you must set the concurrency of the loop to 1). Note the data structure required:

    "Name": "@{items('Apply_to_each')?['{FilenameWithExtension}']}",
    "ContentBytes": {
      $content-type": "@{body('Get_file_content')['$content-type']}",
      "$content": "@{body('Get_file_content')['$content']}"
    }
  • attach the array in the Send Email activity:

  • if you are going to iterate over other folders for other emails, clear the attachments array using Set Variable:

See also