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.




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

14 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Matt Wright
Matt Wright
5 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
1 month 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.

Kindu Melese
Kindu Melese
5 months ago

Hi Matthew
It is really important testimony and I like it

PowerBridge
PowerBridge
4 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
4 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
4 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
4 months ago

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

Gavin Brown
3 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
1 month 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
1 month 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