Skip to content

Gmail — Download attachments

Type: gmail-download-attachments  ·  Package: Gmail v1.0.4  ·  Output: List<string>

Downloads all the attachments of an email to a folder on the machine and returns the list of saved paths. It is the usual step after searching for emails with has:attachment.

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

  • The destination folder is created if it doesn’t exist (including intermediate folders).
  • It downloads every part of the email that has a file name, including embedded images that carry one (logos, signatures). They are the same items listed in the attachments key of Get email by ID.
  • 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. Running the activity twice on the same email gives you numbered copies.
ParameterTypeDefaultDescription
idstring—Message ID.
folderstring—Destination folder. Created if it doesn’t exist.
ParameterTypeDefaultDescription
sessionZoanGmailSession—Gmail — Connect session (inherited inside body).

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

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.
Requested entity was not found.No email with that ID exists in the mailbox.
Folder access errorThe robot cannot create or write to folder (Windows permissions, missing drive).
Gmail — Connect credential = credential("gmail-invoices")
└─ body:
Gmail — Get emails query = "is:unread has:attachment filename:pdf subject:invoice" → output: emails
For each email in emails
└─ Gmail — Download attachments id = email["id"] folder = "C:\invoices\inbox" → output: files
For each path in files
└─ PDF Get Text path = path → output: text
Gmail — Apply label id = email["id"] labels = "Processed"