Events
Microsoft 365 Community Conference
May 6, 2 PM - May 9, 12 AM
Skill up for the era of AI at the ultimate community-led Microsoft 365 event, May 6-8 in Las Vegas.
Learn moreThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
This is an open-source article with the community providing support for it. For official Microsoft content, see Microsoft 365 documentation.
We have a library with a number of folders, and each of the folders contains multiple files. These files need to be sent out as attachments, when needed. There are many use cases for this capability, but the example in this article is related to contract management. As you might have guessed, these documents need to be sent as attachments outside of the company.
Note
If you are new to Power Automate head over to the official documentation to learn more.
In our SharePoint team site we have a Contracts folder and inside this folder we have our partners and customers as sub-folders.
The contract files are located inside the customer/partner folder as below
Using the library menu | click Automate | Power Automate | Create a flow
The flow we are building is an Instant Flow, so in the dialog click "See your flows" to navigate to the Flow editor page.
Choose to create a new flow | Instant-from blank.
Name your flow, choose to "For a selected file" as trigger, and then click Create.
Whenever the flow runs we need some data from the end user. In this case "Recipient Name" and "Recipient Email". We will create two variables:
The next step is to grab the data for the item that started the flow. That way we can verify if the "item" that started the workflow is a file or a folder.
If folder is "true", we will then append the folder name to our variable "FolderName", and use this in the next action to grab all the files properties in the current folder.
We will then use "Apply to each" to append the files' content to our Attachment array variable. The trick here is to append the right content. Thanks to this guide at the Flow forums by Sunay Vaishnav, I finally managed to get this working.
As of this writing, the best way to append SharePoint files to an attachment array is:
{
"Name": @{items('Apply_to_each')?['{FilenameWithExtension}']},
"ContentBytes": @{body('Get_file_content')?['body']}
}
The final action is the "Send email (V2)" action. You will need to populate the action with the following inputs:
The whole Flow should look something like this:
When you are all done, click Save, Test, and Share with your users
The recipient should receive an email with the files attached.
Principal author: Jimmy Hang, MCT, MCSE: Productivity
Microsoft 365 community content feedback
Microsoft 365 community content is an open source project. Select a link to provide feedback:
Events
Microsoft 365 Community Conference
May 6, 2 PM - May 9, 12 AM
Skill up for the era of AI at the ultimate community-led Microsoft 365 event, May 6-8 in Las Vegas.
Learn moreTraining
Module
Best practices for email in SharePoint and Power Automate - Training
Email continues to be the primary and preferred method of communication for many businesses. In some situations, emails are also received as official electronic forms of approval. This module will provide you with a list of best practices that you can follow by using Microsoft Power Automate for outgoing and incoming emails.
Certification
Microsoft Certified: Power Automate RPA Developer Associate - Certifications
Demonstrate how to improve and automate workflows with Microsoft Power Automate RPA developer.