How to export emails with attachments to SharePoint in Power Automate
This tutorial shows how to create a flow in Power Automate to automatically export emails with attachments to a SharePoint library, useful for organizing and sharing files without manual intervention. The solution filters emails by subject, saves the attachment and records basic metadata for later search. The idea is to reduce repetitive work, improve file auditing and facilitate access for team members or stakeholders.
Prerequisites
- Microsoft account with access to Power Automate. For enterprise scenarios, check the license (per-user or per-flow) if you expect to process many emails per day.
- Site and library in SharePoint Online with write permissions for the flow account. Configure columns in the library such as Title (Single line of text), Sender (Single line of text), Subject (Single line of text) and ReceivedTime (Date and Time).
- Mailbox in Exchange Online or Outlook.com accessible by the same account used in Power Automate. Note limits: Outlook.com typically accepts attachments up to 25 MB; Exchange Online may allow larger values depending on tenant configuration (e.g.: 100–150 MB).
- Basic knowledge of building flows in Power Automate (interface and triggers). It is helpful to know how to use expressions like formatDateTime() and concat() to manipulate file names.
Step 1: Create the flow with the trigger "When a new email arrives (V3)"
Open Power Automate, choose "Automated cloud flow" and select the trigger "When a new email arrives (V3)" from the Office 365 Outlook connector. Configure the folder (Inbox) and optionally filter by From, Subject Filter or Importance to reduce unnecessary triggers. For example, if you only need monthly reports, use Subject Filter: "Relatório Mensal" — this can reduce executions from hundreds to a few per month.
// Exemplos de campos do trigger
Folder: Inbox
Include Attachments: Yes
Only with Attachments: Yes
Subject Filter: Relatório Mensal
Explanation: the filter on the trigger avoids costs and throttling. If your flow runs 1000 times per day without need, it will quickly hit usage limits. Start with simple filters and test for a week to adjust.
Step 2: Check if the email has attachments and iterate
Add a simple condition to ensure the email has attachments. The trigger usually provides the Has Attachments property; if not, use the "Get attachments" action and check that the list is not empty. Then use "Apply to each" to process each attachment. It is recommended to set Concurrency Control on the "Apply to each" to 1 if preserving order or avoiding collisions when creating files is important.
// Condição exemplo
Condition: @equals(triggerOutputs()?['body/HasAttachments'], true)
// Apply to each
Select: List of Attachments (do Get attachments ou body('When_a_new_email_arrives')?['Attachments'])
Practical example: if you receive on average 20 emails with attachments per day and each attachment is 2 MB, that amounts to about 40 MB/day → ~1.2 GB/month. Plan quota and automatic cleanup if higher volume is expected (e.g.: >1000 attachments/month).
Step 3: Save each attachment in SharePoint with metadata
Inside the "Apply to each", add the "Create file" action from the SharePoint connector to create the file in the library. Use dynamic content for File Name and ContentBytes. Then add the "Update file properties" action to populate columns like "Sender", "Subject" and "ReceivedTime". Create appropriate columns in the library before running the flow to avoid errors.
// Create file
Site Address: https://contoso.sharepoint.com/sites/Projeto
Folder Path: /Shared Documents/AnexosEmails
File Name: @{items('Apply_to_each')?['Name']}
File Content: @{items('Apply_to_each')?['ContentBytes']}
// Update file properties
ID: ID (da Create file)
Title: @{items('Apply_to_each')?['Name']}
Sender: @{triggerOutputs()?['body/From']}
Subject: @{triggerOutputs()?['body/Subject']}
ReceivedTime: @{triggerOutputs()?['body/DateTimeReceived']}
Practical tip: map Sender to the email address (e.g.: joao.silva@contoso.com) in a text field, and add a "ProcessedBy" column (Choice or Person) if multiple teams are responsible for the files.
Step 4: Handle duplicate names and common errors
To avoid overwriting files with the same names, you can prefix the name with the date/time or use a GUID. You can also create a folder per sender. If you encounter permission or size limit errors, capture them with a "Configure run after" block and send a notification email to the administrator. Also consider logging to a SharePoint list for auditing each run.
// Prefixo com timestamp
File Name: @{formatDateTime(utcNow(),'yyyyMMdd-HHmmss')}_@{items('Apply_to_each')?['Name']}
// Exemplo de ação após erro
Configure run after: has failed
Ação: Send an email (V2) -> Aviso de erro com corpo: @{outputs('Create_file')?['body']}
Notes on limits: SharePoint Online supports large files (up to 250 GB per file, according to current policies), but Power Automate may fail if the attachment is too large to be read by the connector. For high volumes, evaluate ETL solutions or OneDrive for Business as an intermediary repository.
Verify the result
Send a test email with an attachment and the subject that matches the filter. Check the SharePoint library: the file should exist with the correct name and the metadata columns populated. Review the flow run history in Power Automate to see details and error messages if something fails. A well-configured flow shows the execution time (e.g.: 3–7 seconds per attachment) and the payload sent.
If something does not appear, check the connector account permissions, the Folder Path and whether the columns were correctly populated (incompatible types cause failures in the "Update file properties" action).
Conclusion
This automation reduces manual work and centralizes important attachments in SharePoint for easy search. Recommended next steps: add automatic tags with conditional logic, save attachments in folders by sender, or integrate with Power BI for dashboards showing attachment volume and origin. Practical tip: start with simple filters and monitor for 7–14 days to adjust thresholds and avoid noise and errors.