Download Email Attachments

Verb: emailGetAttachment

Downloads all files attached to an email message, returning a list of the paths where they were saved.

Syntax

emailGetAttachment [--filemask(String)] --outputpath(String) --message(EmailMessage) (List<String>)=value

Inputs

Script Designer Required AcceptedTypes Description
--filemask File Extension Optional Text Filter to be applied when searching for the file, using its name and/or extension as a base.
1. The format must be as follows: [Name or part of the file name, spaces are not accepted in this part]. [File extension]. See some examples:
  • *.txt: filters all files with the extension ".txt";
  • name: filters all files that have the word "name" as part of the name;
  • name.txt: filters all files that have the word "name" as their name or part of it and extension "txt".
  • 2. The name of the file is case sensitive.
    --outputpath Directory Required Text Full path to the directory where the downloaded files should be saved.
    --message Message Required Email Message Variable of type Email Message that contains the email with the attachment to be downloaded.

    Outputs

    Script Designer AcceptedTypes Description
    value Directories List List<Text> Returns a list of the paths of files downloaded from Message.

    Example

    After establishing a connection with an email server, the Download Email Attachments command is used to download the files attached to messages whose extension is ".pdf". For these downloaded files to be saved in a directory, the Get System Folder Path command is used to obtain the folder "My Documents", which was informed in the Directory parameter.

    defVar --name currentMessage --type EmailMessage
    defVar --name emailConnection --type EmailConnection
    defVar --name attachmentsDirectory --type List --innertype String
    defVar --name myDocumentsDirectory --type String
    // Using the "Get System Folder" command allows you to obtain the full path to the "My Documents" folder, so that it can be used later in the "Download Email Attachments" command to save the downloaded files.
    getSpecialFolder --folder "MyDocuments" myDocumentsDirectory=value
    imapConnect --mailhost "outlook.office365.com" --mailport 993 --usessl  --username "useremail@email.com" --mailusername "useremail@email.com" --mailpassword userpassword --enableLog  emailConnection=value
    foreach --collection "${emailConnection}" --variable "${currentMessage}"
        emailGetAttachment --filemask "*.pdf" --outputpath "${myDocumentsDirectory}" --message ${currentMessage} attachmentsDirectory=value
    endFor
    emailDisconnect --connection ${emailConnection}
    logMessage --message "${attachmentsDirectory}" --type "Info"
    // Download the attachments and show the paths of the downloaded files.
    // Example: [C:\User\Documents\file.pdf].
    
    You must have access to an email account and enter the host, port, user and password settings to execute the command.

    See Also

  • Apply Classification Filters
  • Apply Search Filters
  • Connect to Exchange Email Server
  • Connect to IMAP Email Server
  • Connect to Outlook Server
  • Connect to SMTP Server
  • Count Emails
  • Delete Email
  • Disconnect from Email Server
  • Move Email
  • Read Email
  • Remove Email Classification Filters
  • Remove Search Filters from Email
  • Reply Email
  • Send Email
  • Split Email Conversations
  • Update Email Information