Power Automate: Save Email Attachments To SharePoint Library

Power Automate: Save Email Attachments To SharePoint Library

Email attachments often need to be saved to SharePoint document library. Power Automate can take any incoming/outgoing message and save their email attachments to SharePoint. It can even tag the attachments or place them in a folder for easier lookup in the future.

Table of Contents
• Introduction: The Legal Department Email Attachments AutomationSetup The SharePoint Document LibraryConfigure The "When A New Email Arrives" Trigger SettingsSave Each Email Attachment To The SharePoint Document LibraryRun The Power Automate Flow To Save Email AttachmentsGroup Email Attachments By The Sender In SharePoint

Lawyers working in the legal department of a healthcare company receive email messages from outside consul. When a new email is received in the shared mailbox it attachments are automatically saved to a SharePoint document library using Power Automate.



The email attachments are tagged with the original email’s subject, from email and received date.




Setup The SharePoint Document Library

Create a new SharePoint Document Library named Legal Conversations with the following columns:

  • Name
  • EmailSubject (single-line text)
  • EmailFrom (single-line text)
  • EmailReceived (single-line text)




Configure The “When A New Email Arrives” Trigger Settings

Open Power Automate and create a new automated flow using the Office 365 Outlook – When A New Email Arrives In A Shared Mailbox (V3) trigger. Choose the Folder named Inbox. Select “Yes” for the Only With Attachments field.



Go to the trigger’s Settings and enable Split On. This tells Power Automate to evaluate each email individually as it arrives in the inbox.




Save Each Email Attachment To The SharePoint Document Library

We want to save all email attachments received to the Legal Conversations SharePoint library. Add an Apply To Each action and choose the Attachments output of the trigger.

Then add a Condition inside of the Apply to Each action. Check whether Attachment Is Inline is equal to true. We do this to exclude any embedded images from the flow such as those found in a signature.



Leave the If Yes case empty. Add an Office 365 Outlook – Get Attachments action to the If No case. Set the Message ID to the message id captured in the trigger. Apply the Attachments Attachment ID dynamic value from the apply to each loop to the Attachment ID field. Use the shared email inbox address as the Original Mailbox Address.

Note: if you are using a personal mailbox instead of a shared mailbox do not fill-in any value for the Original Mailbox Address.



Insert a SharePoint – Create File action and set the Folder Path to the Legal Conversations SharePoint Document Library. Use the Name output by the Get Attachment action as the File Name and the Content Bytes dynamic value as the File Content.




After the file is created insert a SharePoint – Update File Properties action to tag the file with additional metadata. Use the ItemId of the the newly created file. Then supply the Subject, From and Received Timestamp from the flow’s trigger.




Run The Power Automate Flow To Save Email Attachments

We’re done. Save the flow and perform a manual test. Send an email with attachments to the target email address.



When the email is received the flow saves its attachments to the SharePoint document library.



The attachments appear in the document library as shown below.




Group Email Attachments By The Sender In SharePoint

We can take advantage of the SharePoint document library’s settings to display the attachments grouped by the sender. Go to SharePoint and group the files by the EmailFrom field.



Save the updated view as Grouped By Email From and make it a public view.



The email attachments are now grouped by sender. They can be expanded and collapsed.





Questions?

If you have any questions or feedback about Power Automate: Save Email Attachments To SharePoint Library please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.

Matthew Devaney

Subscribe
Notify of
guest

27 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Matt Wright
Matt Wright
9 months ago

Any thoughts on what to do for S/MIME signed documents, where all attachments are embedded in the .smime attachment?

Matt Schaffer
Matt Schaffer
5 months ago
Reply to  Matt Wright

Yes, the file contents of the smime.p7m file is your message (and all of its attachments) encoded in MIME formatting. Simply base64ToString that file’s contents then use some string functions to split out what the actual file attachments are. Make new files using the included base64 file content from the files included inside of that file and presto chango, there’s your attachments from a digitally signed email.

Phu V. Huynh
Phu V. Huynh
1 month ago
Reply to  Matt Schaffer

Hi Matt Schaffer,

Do you have a sample of the working flow that can handle S/MIME?

Kindu Melese
Kindu Melese
9 months ago

Hi Matthew
It is really important testimony and I like it

PowerBridge
PowerBridge
8 months ago

Hey Matthew,

Whenever I try to upload a PDF to SharePoint, I encounter an error saying, “Hmm looks like this file doesn’t have a preview.” Do you have any insights on how to resolve this issue?

Thanks!

Peter van Vliet
8 months ago

Hi Matthew,

This will work great, but I have some questions here.

Shared Mailbox or any other. This flow will be used for an archiving need in the Netherlands. The use case is that for a municipality all emails of Keyusers (mayor and manager, leaders) will be stored indefinitely. Standard users we will have to store the emails for 7 years.

There are several labels and processes behind this structure (Capstone – Archiving law). This flow is setup for a shared mailbox, but we need to have this working for all mailboxes and depending of the adaptive scope of the users this should be stored following the first part.

My guess is that I can add an extra column to the library and store the label or scope name in there that will show the storage length.

Is it correct to state that the Shared Mailbox was an example flow and that this can be used for all emails.

Question is a bit how much data I will store for keyusers when this is forever and if SharePoint is the correct storage location.

mick alford
mick alford
8 months ago

Looked like it was going to work, but the menu and selection options i have are completly different to those in the walkthrough

Johns
Johns
7 months ago

what if the attachment with the same name it over rights the existing file

Gavin Brown
7 months ago

Hi Matt
really love how simple you explain these tasks.
The attachments (pdf) cannot preview in tile view, unless I manually download, how do I get around that?

Izzudin Daud
Izzudin Daud
5 months ago

Hello Matthew,

Need you advice, the flow ran successfully but the attachment was not saved in the assigned folder in the sharepoint. Is there anything might cause this?

The file is in pdf format

mudassir ali
mudassir ali
5 months ago

Hi Mathew, great article, how can i save whole email(.msg file) including the attachments in the SharePoint document library instead of separately saving the attachments, emailfrom, emailsubject etc

Priya
Priya
4 months ago

Hi Matt,
So far the flow works great but I want to replace the 2 excel files in the Sharepoint Folder, every time the email is sent to the Inbox. (The email is delivered once a month with the attachments)
What action can I insert in the flow that performs the above mentioned process?

Thanks in advance

EMCA1
EMCA1
2 months ago
Reply to  Priya

The attachment overwrites itself as long as it’s the same subject line and excel file name. I’ve managed to create a flow with a condition where if the subject contains “RE: “, meaning a reply, then it would just remove the “RE: ” and save it in the same folder.

Shawna
Shawna
3 months ago

Hello! I used this process and it work great, however I cannot seem to limit the file type to PDF. I would like the flow to only create a file in sharepoint if the file is a PDF. How would I accomplish that?

Sharon Lim
Sharon Lim
2 months ago

Thanks for the tutorial. I am able to create the PDF file in sharepoint (including the Get attachment step) but unable to open or preview the file afterwards even if I download it. Getting this last step of the workflow will be a great timesaver for us.

Cristy C
Cristy C
1 month ago

This script worked perfectly. The only problem now is only attaching the .csv file and not the recipient’s email logos.

Peter
1 month ago

Hi Matt,

Is there a way to avoid clogging up the folder with images from email footers?

Cheers!

Peter
1 month ago

Wow, I’ve searched everywhere for an elegant solution to this – there are some pretty far out ways people are doing this with varying success. This is perfect – thank you!

Charlie
Charlie
23 days ago

Hi Matt.

Me Flow was running just fine, until attachment file exceeds 50MB,

I’m not receiving any error message, the Flow just stop working.

Any ideas on how to manage email atrachments bigger than 50MB?

Paul
Paul
19 days ago

Hi Matthew, great blog as always. Do you know if there is a way to get this to work with multiple shared mailboxes? The mailbox field seems to be a party list field and I’ve tried separating addresses with, and ; but it doesn’t even trigger.

Leclercq
Leclercq
16 days ago

Hello,

The flow works and saves the excel file, but the file seems to be corrupted : 

  • in outlook, I read the file with excel,
  • the saved file can be read with excel online app,
  • the excel file can’t be read with excel app,
  • When I download the saved file from SharePoint, if the file is on version 0 then I can open it with Excel … But if the file is in version > 1, then I can’t open the file with the Excel app,
  • Excel script can’t be executed from Power Automate on the saved file (error is “The file format is not recognized. Please verify that the selected workbook is valid.”)
  • if i open the file with excel online app, i can run the excel script.

Do you have an idea how solve the problem ?
Thanks.

Flux.jpg
Antonio Zanutto
Antonio Zanutto
12 days ago

Hi Matthew, first, thanks a lot for your content.
Now, I have a question. I receive emails with attached spreadsheets, I would like to create a flow that would read this attachment and add the content to a sharepoint list everytime a new email arrives.
Is there a way to do this?