Skip to content

Outlook Get Attachments

Type: outlook-get-attachments  ·  Package: Outlook Activities v1.0.4  ·  Output: List<string>

Saves the attachments of an email to a local folder and returns the list of paths of the saved files. It is key in processes that receive documents by email: PDF invoices, Excel spreadsheets, etc.

Given the EntryID of an email (the .Id returned by Outlook Get Emails), it saves all its attachments to outputDir with their original names and returns the resulting paths. Then you process those files with the matching package (Excel, PDF…).

  • If outputDir does not exist, it is created (including intermediate folders).
  • If a file with the same name already exists, it is overwritten. If two attachments of the same email share a name, the last one wins. To keep emails apart, use one folder per email (for example with the received date in the path).
  • Every attachment of the email is saved, including images embedded in the body, if any.
  • The email is not modified.
ParameterTypeDefaultDescription
entryIdstring—EntryID of the email (from email.Id).
outputDirstring—Local folder where attachments are saved. Created if missing.
ParameterTypeDefaultDescription
sessionZoanOutlookSession—Session from Outlook Connect. Inherited inside the Connect body; without a session the default account is used.

Returns a List<string> with the full path of each saved file (outputDir + attachment name), in the order they appear in the email. If the email has no attachments, it returns an empty list.

MessageCause and fix
'entryId' is required. / 'outputDir' is required.The parameter is missing or the expression returned null. Check the email variable.
Outlook error when opening the itemThe EntryID does not belong to an email in this profile (it was moved to another mailbox, deleted, or comes from another account). Use the .Id from a recent read.
Path access errorThe robot cannot write to outputDir. Use a folder with write permissions.

Save the attachments of each email in its own folder and process the spreadsheets:

For Each items = emails itemVariable = email
└─ activities:
Outlook Get Attachments entryId = email.Id outputDir = pathJoin("C:/invoices", email.SentAt.ToString("yyyyMMdd-HHmmss")) → output: files
For Each items = files itemVariable = file
└─ activities:
If condition = file.EndsWith(".xlsx")
└─ then:
Read Excel Sheet path = file → output: data
... process ...