Delete Email

Deletes an email message from the email server.

Command availability: IBM RPA SaaS and IBM RPA on premises


Deletes an email message from the email server, moving it to the trash.

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.

emailDelete --message(EmailMessage)


Input parameters

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
Message message Required Email Message Variable of type Email Message that contains the email to be deleted.


Deletes email messages, from the specified email server, that meet the specifications of the filter defined in Apply Search Filters.

defVar --name emailConnection --type EmailConnection
defVar --name messageToDelete --type EmailMessage
defVar --name from --type List --innertype String --value "[]"
defVar --name subject --type List --innertype String --value "[Enter here the subject of the email message that will be deleted]"
imapConnect --mailhost "" --mailport 993 --usessl--username "" --mailusername "" --mailpassword userpassword --enableLogemailConnection=value
// Apply filters in the "From" and "Subject" fields in the connection with the returned email server, so that when using the connection again, only the email message whose filter was applied will be deleted.
emailApplySearchFilters --from ${from} --subjectdirective "All" --inclusivesubject ${subject} --wordsdirective "All" --connection ${emailConnection}
foreach --collection "${emailConnection}" --variable "${messageToDelete}"
emailDelete --message ${messageToDelete}
// Delete the message, moving it to the email server's trash.
Note:Use a valid email connection to run this example script.


The Delete Email command must be used within the repetition structure For Each.