Integrating IBM RPA with email providers using app passwords

Learn how to integrate IBM RPA with email providers by using app passwords.

About this task

In this tutorial, you learn how to use app passwords to safely integrate IBM RPA with email providers. App passwords are strong passwords that services like email providers can generate to enable that apps access their accounts. It's recommended that you use app passwords instead of basic authentication if your email provider has this feature. To illustrate this concept, follow the steps in this tutorial to build a script that reads emails and logs their subject and body.

Before you begin

  • Make sure that your firewall does not block access to your email provider.

  • Make sure that your environment does not block the email protocol that your email provider uses like IMAP, Exchange, or SMTP.

  • Make sure that your email account has app passwords enabled. It is possible that you don't have permissions to create app passwords because organizational settings block this feature, or you might need to enable two-factor authentication for your account, among other reasons.

    🛈 Refer to your email provider's documentation for details on how to enable app passwords. If you have a work account for an email provider, refer to your organization's processes to request an app password for your account.

  • Make sure that your email provider accepts app password connections. It is possible that you need to change settings on your email provider to allow that accounts connect using app passwords, sometimes referred to as basic authentication.


  1. Generate an app password
  2. Store the app password on the IBM RPA Vault
  3. Create the script

Generating an app password

To generate app passwords, your email provider must have the feature to generate them and your organization's environment must not block this feature. Each email provider has their own method to generate app passwords, refer to the documentation of your email provider to generate an app password.

Storing the app password on the IBM RPA Vault

Store the app password on IBM RPA Vault to secure it. Then, you can safely use it on your scripts. In this tutorial, you store the app password on your tenant's system vault. See Configuring the IBM RPA Vault to learn more about configuring the system vault.

  1. Log in to IBM RPA Control Center.
  2. On the menu, click Credentials.
  3. On the Credentials tab, click Create credential.
  4. On Name, enter the name of the credential, for example: email_provider_app_pw.
  5. On Username, enter the username of your email provider's account, for example:
  6. On Password, enter the app password.

Creating the script

You can reference your app password, safely stored on a credential, on your script.

  1. Log in to IBM RPA Studio.
  2. Create a script (.wal file).

Connecting to the email provider

  1. Drag the Get Vault Item command to your script.
    1. On Name, enter your credential's name from the Store the app password on the vault step. For example: email_provider_app_pw.
    2. Enable System.
    3. On User Name, enter emailProviderUsername.
    4. On Password, enter emailProviderAppPassword.
  2. Drag the Connect to IMAP Email Server command to your script.
    1. On Email, enter ${emailProviderUsername}.
    2. On Password, enter ${emailProviderAppPassword}.
    3. On IMAP address, enter your email provider's IMAP address. In this tutorial, you use
    4. On Port, enter your email provider's IMAP communication port. In this tutorial, you use 993.
    5. Enable Use SSL.

Looping through emails to log their content

  1. Create a new variable called emailMessageInstance of type Email Message.
  2. Drag the For Each command below the Connect to IMAP Email Server command. This command is required to read emails from the email account.
    1. On Collection, enter ${imapConnectionToEmailProvider}.
    2. On Variable, enter ${emailMessageInstance}.
  3. Drag the Read Email command between the For Each construct.
    1. On Message, enter ${emailMessageInstance}.
    2. On Subject, enter emailMessageSubject.
    3. On Email Body, enter emailMessageBody.
  4. Drag the Log Message command below the Read Email command.
    • On Message, use the following text:
Subject: ${emailMessageSubject}

Body: ${emailMessageBody}


You must have the following script as a result:


You can copy the script syntax on the Results section.

Run the script. On IBM RPA Studio's Output panel, you should see the subject and body of each email message from your email account.


You can copy this tutorial's script on the following code block:

defVar --name emailProviderUsername --type String
defVar --name emailProviderAppPassword --type SecureString
defVar --name imapConnectionToEmailProvider --type EmailConnection
defVar --name emailMessageInstance --type EmailMessage
defVar --name emailMessageSubject --type String
defVar --name emailMessageBody --type String
getVaultItem --name email_provider_app_pw --system  emailProviderUsername=userName emailProviderAppPassword=password
imapConnect --mailhost "" --mailport 993 --usessl  --mailusername "${emailProviderUsername}" --mailpassword "${emailProviderAppPassword}" imapConnectionToEmailProvider=value
foreach --collection "${imapConnectionToEmailProvider}" --variable "${emailMessageInstance}"
	emailRead --message ${emailMessageInstance} emailMessageSubject=subject emailMessageBody=body
	logMessage --message "Subject: ${emailMessageSubject}\r\n\r\nBody: ${emailMessageBody}\r\n\r\n------" --type "Info"

What to do next

This tutorial explains the basics about integrating IBM RPA with email providers. The email parsing applied was logging, but you could use your own parsing logic to achieve your goal.