Outlook.com Attachment Saver to OneDrive
Automatically save all attachments from incoming Outlook.com emails to a dedicated OneDrive folder, organized by sender and date.
Provided as-is, without warranty of any kind. Review and test each pattern in a non-production environment before deploying it to live automations. See our Terms.
Overview
This flow automatically saves every attachment from incoming Outlook.com email into a dedicated OneDrive for Business folder, organized by sender email address and the date the email arrived. It demonstrates a connector-first attachment handler pattern: a polling Outlook.com mail trigger that fetches only emails carrying attachments, paired with a OneDrive for Business CreateFile loop that materializes each attachment into a sender/date hierarchy. The flow ships in the Off state — turning it on requires only authorizing the two existing connection references and (optionally) overriding the two environment variables.
Use Case
Knowledge workers, finance teams, and operators who use a personal Outlook.com mailbox alongside their corporate Microsoft 365 OneDrive frequently need a permanent, browsable archive of email attachments. Manually downloading and filing each attachment is tedious and error prone, especially when receipts, contracts, statements, or media files arrive at high volume. This flow replaces that manual workflow with a 3-minute polling check that, on every new attachment-bearing email, drops every attachment into a \Email Attachments\<sender>\<yyyy-MM-dd>\<original filename> path on OneDrive — making it trivial to find later by who sent it and when.
Flow Architecture
When a New Outlook Com Email Arrives With Attachments
Outlook.com OnNewEmailV2Polls the configured Outlook.com folder every 3 minutes. `fetchOnlyWithAttachment` is set to `true` so the trigger only fires on emails that carry attachments, and `includeAttachments` is set to `true` so the attachment binary content (`ContentBytes`) is delivered with the trigger payload — eliminating the need for a follow-up `GetAttachment` call. Folder path is parameterized via `flowlibs_OutlookComFolderPath` (default `Inbox`), and `importance` is left at `Any`.
Initialize Sender Email Address
Initialize VariableCaptures the trigger's `body/From` value into `varSenderEmail`, falling back to the literal string `unknown-sender` via `coalesce()` if the From header is missing or null. This guards against trigger payload variations and ensures the downstream folder path is always valid.
Initialize Date Folder Stamp
Initialize VariableComputes today's date in `yyyy-MM-dd` format using `formatDateTime(utcNow(), 'yyyy-MM-dd')` and stores it in `varDateFolderStamp`. This becomes the second segment of the per-email folder hierarchy, giving each day its own subfolder under each sender.
Initialize Safe Sender Folder Name
Initialize VariableStrips the nine characters that are invalid in OneDrive/SharePoint folder names (`< > : " / \ | ? *`) from `varSenderEmail` to produce `varSafeSenderFolderName`. Without this sanitization, an email From header containing `Display Name <email@domain.com>` would fail the `CreateFile` call because of the `<` and `>` characters.
Compose Target OneDrive Folder Path
ComposeBuilds the final folder path string by concatenating the base path env var, the sanitized sender folder name, and the date stamp: `concat(parameters('OneDriveAttachmentsFolderPath'), '/', variables('varSafeSenderFolderName'), '/', variables('varDateFolderStamp'))`. Pre-computing this once keeps the loop body simple and makes the path inspectable in run history.
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_OneDriveAttachmentsFolderPath | String | /Email Attachments | Base OneDrive folder under which the per-sender, per-date hierarchy is created. Override per environment to point at a different OneDrive root. |
| flowlibs_OutlookComFolderPath | String | Inbox | Outlook.com mail folder the trigger polls. Change to a custom folder name (or path like `Inbox/Receipts`) to scope the flow to specific emails. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| Outlook.com | shared_outlook | OnNewEmailV2 (trigger) |
| OneDrive for Business | shared_onedriveforbusiness | CreateFile |
Note — All connections are referenced as solution connection references; the flow is portable between environments as long as a connection is mapped at import time.
Customization Guide
Almost every realistic variant of this flow can be implemented by changing environment variable values. A few cases require small edits inside the flow definition — those are called out explicitly below.
- Change the source folder
- Override flowlibs_OutlookComFolderPath to monitor a custom Outlook.com folder (e.g., a folder rule routes vendor invoices into an Invoices folder; set this var to Invoices to scope the flow to that subset).
- Change the destination root
- Override flowlibs_OneDriveAttachmentsFolderPath to write to any OneDrive folder. The base folder must exist; the per-sender and per-date subfolders are auto-created.
- Change the polling interval
- The trigger's recurrence block is set to { frequency: 'Minute', interval: 3 }. Adjust frequency (Second / Minute / Hour / Day) and interval to trade off latency for run-quota consumption.
- Filter by sender, importance, or subject
- The OnNewEmailV2 trigger exposes optional from, to, cc, toOrCc, importance, subjectFilter, and attachmentFilter parameters. Add any of these to scope the trigger to a more specific set of emails — for example, from: 'noreply@bank.example' to archive only bank statements.
- Group by month instead of day
- Change formatDateTime(utcNow(), 'yyyy-MM-dd')
Key Expressions
The flow is intentionally light on Power Fx / WDL gymnastics — the heaviest expressions are the branch-name concatenation and the approval outcome check. They are listed below in the order they appear in the flow.
EXPR.01Sender fallback
Used in `Initialize Sender Email Address`. Defaults the sender to a literal string when From is null, preventing an empty folder segment.
EXPR.02Date folder stamp
Used in `Initialize Date Folder Stamp`. Produces a sortable date folder name in UTC.
EXPR.03Strip invalid folder-name characters
Used in `Initialize Safe Sender Folder Name`. Nine nested `replace()` calls strip the characters disallowed in OneDrive/SharePoint folder names (`< > : " / \ | ? *`).
EXPR.04Compose target folder path
Used in `Compose Target OneDrive Folder Path`. Assembles the per-email destination folder path from the env-var base + sender + date.
EXPR.05Attachments array
Used in `For Each Attachment In Email`. Iterates the array of attachment objects delivered by the trigger (because `includeAttachments` is `true`).
EXPR.06Attachment filename
Used in `Save Attachment To OneDrive`. Original attachment filename, used as-is for the OneDrive file name.
EXPR.07Decode attachment bytes
Used in `Save Attachment To OneDrive`. Decodes the base64 attachment payload into a true binary file body. Without this, OneDrive would store the base64 text.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.