Skip to content

Outlook 365 — Download attachments

Type: outlook365-download-attachments  ·  Package: Outlook 365 v1.0.4  ·  Output: List<string>

Downloads an email’s file attachments to a folder on the machine and returns the list of saved paths. It is the usual step after searching for emails with attachments.

It works on the session created with Outlook 365 — Connect. Pass it in the session parameter, or place this activity inside the body of Outlook 365 — Connect to inherit it automatically.

  • The destination folder is created if it doesn’t exist (including intermediate folders).
  • Each file is saved with its original name. It never overwrites: if a file with that name already exists, it saves name (1).ext, name (2).ext, and so on. So running the activity twice on the same email gives you numbered copies.
  • It downloads file attachments, including images embedded in the body (logos, signatures). Attached emails (a .msg inside the email) and attachments that are OneDrive/SharePoint links are skipped.

To know beforehand whether an email has attachments, check its hasAttachments key or filter with filter = "hasAttachments eq true" in Get emails.

ParameterTypeDefaultDescription
idstring—Message ID.
folderstring—Destination folder. Created if it doesn’t exist.
ParameterTypeDefaultDescription
sessionZoanOutlookMailSession—Outlook 365 — Connect session (inherited inside body).

Returns a List<string> with the full path of each saved file, in the order Graph lists the attachments. If the email had no file attachments, the list is empty (it does not fail). Loop over it with For each or access an item by index (paths[0]).

MessageCause and fix
'id' is required.id is empty or the expression returned null.
'folder' is required.folder is empty or the expression returned null.
Graph error ErrorItemNotFoundNo email exists with that ID anymore (deleted or moved). Download before moving.
Folder access errorThe robot cannot create or write to folder (Windows permissions, missing drive).
Outlook 365 — Connect credential = credential("m365-invoices")
└─ body:
Outlook 365 — Get emails folder = "inbox" filter = "hasAttachments eq true and isRead eq false" → output: emails
For each email in emails
└─ Outlook 365 — Download attachments id = email["id"] folder = "C:\invoices\inbox" → output: files
For each path in files
└─ PDF Get Text path = path → output: text
Outlook 365 — Mark read/unread id = email["id"]