How to divert email attachments to SharePoint

Step by step flow for sending email attachments to a SharePoint document library - Basic level flow

This flow activates when an email is received and save the attachment into a document library. Useful for mass email collections and saves time from needing to extract attachments separately.

Why do we need it?

For work involving massive amounts of emails with attachments, such as invoices, travel statements, tickets, etc, there is typically someone on mailbox who will need to collect the emails and manually download the attachments into a folder. Doing it manually is a slog and very soul-destroying, not to mention potential errors in leaving out files.
How does it work?
We ask Power Automate to automatically trigger every time an email arrives. It then detects if an attachment is present. If so then it strips out the attachment and deposits it into a SharePoint Document Library. If the email doesn't have an attachment, then it is ignored. You simply set this up to run and it just works.

Objective

Create an automatic trigger using the "When a new email arrives (V3) which activates when an email arrives.
  1. To - Identifies emails that have emails matching this email. You can add multiple emails, and though it uses profiles to prepopulates, you can use any kind emails.
  2. From - As above, but using the From emails
  3. Includes Attachments - This needs to be Yes in order for this work.
  4. Only with Attachments - This also needs to be Yes in order to work.
  5. Folder - Indicate which folder the email comes into. typically Inbox, but you can use other folders if you have multiple flows doing the same thing.

Trigger - When a new email arrives (V3)

power automate, power bi, automated trigger, scheduled flows, automated flows, expressions, dynamic
power automate, power bi, automated trigger, scheduled flows, automated flows, expressions, dynamic
Adding a condition after this helps decide which attachment criteria to place. I've included this so that all attachment will come through, so the "image00" is just a nonsense statement

Condition

power automate, power bi, automated trigger, scheduled flows, automated flows, expressions, dynamic
power automate, power bi, automated trigger, scheduled flows, automated flows, expressions, dynamic
Under the Yes branch for this condition statement, we select the output "Attachments" and use the expression below. This ensures that the attachment is selected.
We leave the False branch false as there is no other option.

Branch - True

power automate, power bi, automated trigger, scheduled flows, automated flows, expressions, dynamic
power automate, power bi, automated trigger, scheduled flows, automated flows, expressions, dynamic
triggerOutputs()?['body/attachments']
Under the Apply to each in the True branch, we need to have a "Create File" so that the attachment is "created" in the area that we want.

Branch - True - Create File

power automate, power bi, automated trigger, scheduled flows, automated flows, expressions, dynamic
power automate, power bi, automated trigger, scheduled flows, automated flows, expressions, dynamic
items('Apply_to_each')?['name']
File Name
File Content
items('Apply_to_each')?['contentBytes']
Once the flow is completed, save it and be sure to test the flow before making it active. You will need to kick it off from the triggers illustrated in the first section and the result should work fine.

Overall Flow

power automate, power bi, automated trigger, scheduled flows, automated flows, expressions, dynamic
power automate, power bi, automated trigger, scheduled flows, automated flows, expressions, dynamic
  • This simple flow is easy to setup and easy to use. Requires no user intervention at all.

  • Emails that have graphics or company logo images are also considered "attachment", so these will also be captured. For these, you can either setup a yes/no flow for if attachments are images, or you can just manually remove these periodically. I honestly didn't mind the latter as they only constituted less than 5% of the overall collected attachments.

  • If you want to scrape the actual data of the email instead of just the attachment, then I have another page on this topic. This process scans the email, parses the data into html values, and then defines these data before entry into a Microsoft List. It also has attachment scraping as well, so worthwhile checking out.

Final thoughts