You can use Power Automate to automatically move your email attachments to a SharePoint document library. In this post I’ll show you how to move PDF (or any other file type) attachments to a SharePoint document library.
This is the flow that we will build:
1. Start by creating an automated cloud flow:
2. Give your flow a name then select the flow’s trigger as When a new email arrives (V3):
3. Set the following two properties of the When a new email arrives (V3) trigger:
|Include Attachments||Should the response of the trigger include the attachments content.|
|Only with Attachments||If set to true (Yes), only emails with an attachment will be retrieved. Emails without any attachments will be skipped. If set to false (No), all emails will be retrieved.|
4. Add an Apply to each loop (2) and set Attachments as the output (3) as shown below. The loop will save each attachment to a SharePoint Document Library of our choice:
5. Add a Condition to check the attachment’s filename (4). We want to check if the attachment name ends with ‘pdf’. If the attachment name ends with ‘pdf’ we want to save it to our SharePoint library. Change the condition to save other file types.
6. Add a SharePoint Create file action (5). Select the SharePoint site and document library.
7. Finally select the attachment’s filename and file content (5) from Dynamic content:
Saving different File Types
The flow Condition can be changed to support any file type or even multiple different file types, for example:
Sample Runtime output: Save PDF email attachments to a SharePoint Document Library
- The SharePoint document library Lib1 is empty:
2. Send an email with four attachments, two of which are PDF documents:
3. The flow is triggered and starts to run:
4. Soon two PDF files appear in the SharePoint document library:
The example runtime output below shows that the Apply to each loop ran four times. This means that four files were sent as file attachments in the email but only two files (PDF) were saved to SharePoint:
Sample Runtime output: Saving selected file types to a SharePoint Document Library
When a new email arrives (V3) – This operation triggers a flow when a new email arrives. It will skip any email that has a total message size greater than the limit put by your Exchange Admin or 50 MB, whichever is less. It may also skip protected emails and emails with invalid body or attachments.