Download Email Attachments

Downloads attachments from email messages.

Command availability: IBM RPA SaaS and IBM RPA on premises

Description

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

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

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

Dependencies

Input parameter

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
File Extension filemask 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 without spaces].[File extension]. 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 gets the file with this exact name and extension.
Directory outputpath Required Text Full path to the directory where the downloaded files should be saved.
Accept Inline Attachments acceptinlineattachments Optional Boolean Use to list the attachments that come in the email body.
Message message Required Email Message Variable of type Email Message that contains the email with the attachment to be downloaded.

Output parameter

Designer mode label Script mode name Accepted variable types Description
Directories List value 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 with the .pdf extension. The Get System Folder Path command is used to obtain the "My Documents" folder to save the files, using 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].