How to save PDF email attachments to a SharePoint Document Library using Power Automate

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:

Image of the flow that we will build

1. Start by creating an automated cloud flow:

Select automated cloud flow

2. Give your flow a name then select the flow’s trigger as When a new email arrives (V3):

Set flow a name then select the flow's trigger

3. Set the following two properties of the When a new email arrives (V3) trigger:

When a new email arrives (V3) trigger
Propertydescription
Include AttachmentsShould the response of the trigger include the attachments content.
Only with AttachmentsIf 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:

Apply to each loop

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.

Flow condition to check for filename ending with PDF

6. Add a SharePoint Create file action (5). Select the SharePoint site and document library.

SharePoint Create file action.
SharePoint Create file action.

7. Finally select the attachment’s filename and file content (5) from Dynamic content:

SharePoint Create file action
Create file action will create a file in a document library called Lib.

Saving different File Types

The flow Condition can be changed to support any file type or even multiple different file types, for example:

The flow Condition changed to support  multiple different file types.
The Condition can be changed to support any file type such as pdf, docx and xlsx etc.

Sample Runtime output: Save PDF email attachments to a SharePoint Document Library

  1. The SharePoint document library Lib1 is empty:
Empty document library Lib1
Empty document library Lib1

2. Send an email with four attachments, two of which are PDF documents:

Send email with four attachments, only two of which are PDF documents:
Sending a test email message with four file attachments

3. The flow is triggered and starts to run:

The flow is triggered
The flow has started to run

4. Soon two PDF files appear in the SharePoint document library:

Document library Lib1 now contains two PDF files

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:

Example Runtime output

Sample Runtime output: Saving selected file types to a SharePoint Document Library

The flow Condition changed to support  multiple different file types.
Sample Runtime output: Saving selected email attachments to a SharePoint Document Library

Notes

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Website Built with WordPress.com.

Up ↑

%d bloggers like this: