IMAP Save Attachment
IMAP Save Attachment
Section titled “IMAP Save Attachment”Type: imap-save-attachment · Package: SMTP / IMAP Email Activities v1.0.5 · Output: List<string>
Downloads and saves the attachments of an email to a local folder, with their original names. Key in processes that receive documents by email (invoices, spreadsheets) to process them afterwards, without loading the bytes into memory with IMAP Read.
How it works
Section titled “How it works”Given the mailId of an email (the .Id returned by IMAP Read), it opens folder in read-only mode, downloads the message and saves its attachments to outputPath:
- If
outputPathdoes not exist, it is created. - If you set
attachmentName, only attachments with that exact name (case-insensitive) are saved; if you omit it, all are saved. - Each file keeps its original name (without paths); an attachment with no name is saved as
attachment_N. If a file with that name already exists, it is overwritten. - It does not change the email’s state (it stays unread if it was).
Use the same folder you read the email from: the UID is only valid within its folder.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
host | string | — | IMAP server. |
username | string | — | Username. |
password | credential | — | Password or App Password. Use credential("name")["password"]. |
mailId | string | — | Email UID (from email.Id). Must be numeric. |
outputPath | string | — | Local folder where attachments are saved. Created if missing. |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
port | int | 993 | IMAP port. |
folder | string | "INBOX" | Folder that holds the email. |
attachmentName | string | — | Exact name of the attachment to save. If omitted, all are saved. |
security | string | "ssl" | Encryption: auto, none, ssl or starttls. |
Output
Section titled “Output”Returns a List<string> with the full path of each saved attachment, in the order they appear in the email. If none was saved, the list is empty. The log says how many attachments were saved; if you set attachmentName and it is not in the email, it warns The requested attachment was not found in the email. Since version 1.0.5 the output is declared and the Designer offers where to store it.
Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
Invalid 'mailId'. It must be the numeric UID returned by imap-read. | mailId is not a number (for example, an Outlook .Id or empty text). Pass email.Id from IMAP Read. |
'mailId' is required. / 'outputPath' is required. | The parameter is missing or the expression returned null. |
| Message not found error | The email is no longer in folder (it was moved or deleted) or was read from another folder. |
| Authentication or connection error | Same as in IMAP Read. |
Example
Section titled “Example”Save each email’s attachments in its own folder and check what arrived:
IMAP Read host = "imap.gmail.com" username = credential("mail-bot")["user"] password = credential("mail-bot")["password"] subject = "Invoice" hasAttachments = true → output: emailsFor Each items = emails itemVariable = email └─ activities: IMAP Save Attachment host = "imap.gmail.com" username = credential("mail-bot")["user"] password = credential("mail-bot")["password"] mailId = email.Id outputPath = "C:/invoices/" + email.Id → output: files Log message = count(files) + " file(s) from " + email.FromRelated activities
Section titled “Related activities”- IMAP Read — get the emails (and their
mailId). - List Files — check what ended up in the folder.