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.
Procedure
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.
- Log in to IBM RPA Control Center.
- On the menu, click Credentials.
- On the Credentials tab, click Create credential.
- On Name, enter the name of the credential, for example:
email_provider_app_pw
. - On Username, enter the username of your email provider's account, for example:
example@example.com
. - On Password, enter the app password.
Creating the script
You can reference your app password, safely stored on a credential, on your script.
- Log in to IBM RPA Studio.
- Create a script (
.wal
file).
Connecting to the email provider
- Drag the Get Vault Item command to your script.
- On Name, enter your credential's name from the Store the app password on the vault step. For example:
email_provider_app_pw
. - Enable System.
- On User Name, enter
emailProviderUsername
. - On Password, enter
emailProviderAppPassword
.
- On Name, enter your credential's name from the Store the app password on the vault step. For example:
- Drag the Connect to IMAP Email Server command to your script.
- On Email, enter
${emailProviderUsername}
. - On Password, enter
${emailProviderAppPassword}
. - On IMAP address, enter your email provider's IMAP address. In this tutorial, you use
imap.gmail.com
. - On Port, enter your email provider's IMAP communication port. In this tutorial, you use
993
. - Enable Use SSL.
- On Email, enter
Looping through emails to log their content
- Create a new variable called
emailMessageInstance
of typeEmail Message
. - Drag the For Each command below the Connect to IMAP Email Server command. This command is required to read emails from the email account.
- On Collection, enter
${imapConnectionToEmailProvider}
. - On Variable, enter
${emailMessageInstance}
.
- On Collection, enter
- Drag the Read Email command between the For Each construct.
- On Message, enter
${emailMessageInstance}
. - On Subject, enter
emailMessageSubject
. - On Email Body, enter
emailMessageBody
.
- On Message, enter
- 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.
Results
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 "imap.gmail.com" --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"
endFor
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.