MS Flow To Save Email Attachments To SharePoint Library

In this article, we will see how to save email attachments to SharePoint document library.

In this article, we will create an MS flow which will trigger when an email with attachment/s has arrived in our Outlook 365 mailbox. 
 
Let us start with asking why would we need to save email attachments to SharePoint library. To answer this, there can be a few use cases where we would need this. I can think of the following ones. 
  • An email with attachment takes a lot of space. You wanted to store all your email attachments to a library for future references and archive your email.
  • You have shared mailbox and wanted to keep all attachments received in the shared mailbox to the library.
  • You wanted to take your email attachments with some metadata (values) to refer to it later.
If you still think this is not a valid use case, I would recommend you read this article once. You will surely learn about the below triggers/actions which can be used in MS Flow. 
  • Trigger Point  - When new email arrives
  • Action - Apply to each(conditional)
  • Action - Create a file(SharePoint)
Let's get started.
 
Step 1  - Create a new MS flow 
  •  Visit here.
  • Click on My Flows-> New-> Automated - from blank.
MS Flow To Save Email Attachments To SharePoint Library
 
Step 2 -  Name your workflow and select Trigger Point
  • Name your workflow - "Add email attachment to SharePoint Library".
  • On Search Connector and triggers, filter by 'Office 365 Outlook' category.
  • Select Trigger 'When a new email arrives' .
MS Flow To Save Email Attachments To SharePoint Library
 
Step 3  - Configure Trigger Point
  • First, select 'Has attachment' and 'Include attachments' to Yes - This will filter so that MS flow is triggered only when email arrived with attachments.
  • You can apply other filters also, like if you want it to only trigger when someone is in 'To' list or 'CC' list or either in 'To' or 'CC'
  • 'From' field - If you want only trigger MS flow if received from a particular email address, 
  • Subject field - if you want to only trigger MS flow if you received a particular subject, please note this is like 'contains' in the subject.
MS Flow To Save Email Attachments To SharePoint Library
 
Step 4 - Iterate Loop for multiple attachments
  • Now we wanted to support multiple attachments, so first we will create a new step as 'Apply to each'.
  • Select output as 'Attachments' (refer below screenshot) - this object is what will populated by above trigger point step containing all the references to attachments.
  • This will make sure it loops through each attachment in the mail.
MS Flow To Save Email Attachments To SharePoint Library
 
Step 4 - Add action to create file in SharePoint
  • Click on Add action (make sure you are doing this within 'Apply for each'  step).
  • Select 'Create a file' action from SharePoint category
MS Flow To Save Email Attachments To SharePoint Library
 
Step 5 - Configure action create a file.
  • Select Site Address - URL of your site collection
  • Select Folder - You can either select a particular document library or folder within a document library.
  • File Name - Select Attachment Name from the dynamic content window.
  • File Content - Select Attachment Content from dynamic content window.
MS Flow To Save Email Attachments To SharePoint Library
 
Below is how your whole MS flow should look like
 
MS Flow To Save Email Attachments To SharePoint Library
 
Step 6  - Test 
 
That's it, now we have everything setup. Let us test the flow.
  • Send an email to any user and add multiple attachments.
  • Check for an email in your Outlook.  Below is a sample of an email I sent.
MS Flow To Save Email Attachments To SharePoint Library
  • Wait for some time to check the MS Flow history. 

    • You should get the Success message in MS Flow history.
MS Flow To Save Email Attachments To SharePoint Library
  • Go to Your document library and you should see attachments being added as document in document library
MS Flow To Save Email Attachments To SharePoint Library
 
This concludes our article. In this article, we have learned to create an MS flow which will trigger when an email with attachment/s has arrived in Outlook 365 mailbox.
 
Hope this helps...Thanks for reading..!