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 Automation
• Setup The SharePoint Document Library
• Configure The "When A New Email Arrives" Trigger Settings
• Save Each Email Attachment To The SharePoint Document Library
• Run The Power Automate Flow To Save Email Attachments
• Group Email Attachments By The Sender In SharePoint
Introduction: The Legal Department Email Attachments Automation
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.
Did You Enjoy This Article? 😺
Subscribe to get new Power Apps & Power Automate articles sent to your inbox each week for FREE
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.
Any thoughts on what to do for S/MIME signed documents, where all attachments are embedded in the .smime attachment?
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.
Hi Matt Schaffer,
Do you have a sample of the working flow that can handle S/MIME?
Hi Matthew
It is really important testimony and I like it
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!
PowerBridge,
I was missing the Get Attachments step in my tutorial. It has now been fixed 🙂
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.
Looked like it was going to work, but the menu and selection options i have are completly different to those in the walkthrough
what if the attachment with the same name it over rights the existing file
Johns,
The attachment will be overwritten just like in Windows explorer. If you do not like this you can build in a condition action to check for an existing filename.
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?
Gavin Brown,
I needed to update my tutorial. There was a Get Attachments from Outlook step missing. Now I’ve added it and you will be able to see the file contents.
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
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
Mudassir,
I have an article about this very topic 🙂
https://www.matthewdevaney.com/power-automate-save-an-email-message-to-sharepoint/
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
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.
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?
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.
This script worked perfectly. The only problem now is only attaching the .csv file and not the recipient’s email logos.
Hi Matt,
Is there a way to avoid clogging up the folder with images from email footers?
Cheers!
Peter,
I believe there is a property of the attachments called isInline. If you put a condition where isInline equals false and extract only those attachments it should help.
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!