Integrating IBM RPA with Outlook desktop application
Learn how to integrate IBM RPA with the Outlook desktop application.
About this task
In this tutorial, you learn how to integrate IBM RPA with the Outlook desktop application by using the Connect to Outlook server (outlookConnect
)command.
Follow the steps in this tutorial to build a script that opens the Outlook application if it is not open yet, filter emails, and logs their content.
Before you begin
- Ensure that Outlook is installed in your machine.
- Outlook desktop must be open so IBM RPA can establish a connection to the application.
- If you have logged in with your email account in the Outlook desktop application, you don't need to enter your email password on the Connect to Outlook server (
outlookConnect
) command. - Ensure that you have installed the 64-bit version of the Outlook application.
Creating the script
- Log in to IBM RPA Studio.
- Create a new script (
.wal
file).
Ensuring Outlook is open
As Outlook must be open so IBM RPA can establish the connection, let's make sure that it is. You can use IBM RPA's recorder** tool to map Outlook application's menu and make it even easier to build your script.
- With your Outlook desktop application opened, click the Start Recorder button in IBM RPA Studio's ribbon. After loading the drivers, the recorder's menu bar appears at the top of the screen.
- Place your mouse cursor on the Outlook panel and hold the
Ctrl + Shift
key on your keyboard until the panel is highlighted in green. - On the recorder bar, click Window > Wait for window to appear.
- The Wait for Window to appear (
waitWindow
) opens. Notice how some parameters are already filled.- On Success, enter
windowStatus
and click Save.
- On Success, enter
- Click Home > New Routine.
- On Name, enter
openOutlook
and click Save. - Drag the Launch and Attach Window (
launchWindow
)command to your script.- On Executable, click the File selection helper button and search for the
OUTLOOK.EXE
executable. The file path can look like:C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE
. - Click Save.
- On Executable, click the File selection helper button and search for the
- In the script's main routine, drag the Run Subroutine if (
gosubIf
) command.- On Name, select
openOutlook
. - On Left Operand, enter
${windowStatus}
. - On Operator, select
Is true
. - Enable Negate.
- On Name, select
Connecting to Outlook Server
- Drag the Connect to Outlook Server (
outlookConnect
) command to your script.- On Email, enter the email that is connected to the Outlook application.
- On Connection, enter
outlookConnection
and click Save.
Filtering emails
- Create a new variable called
keyWords
of typeList<Text>
, add words that you want to filter for. In this tutorial, the word istesting
. - Drag the Apply Search Filters (
emailApplySearchFilters
) command to your script.- On Connection, enter
${outlookConnection}
. - Enable Search all Folders.
- On Inclusive Words in the Subject, enter
${keyWords}
and click Save.
- On Connection, enter
Reading and logging the contents of filtered emails
- Create a new variable called
emailMessageInstance
of typeEmail Message
. - Drag the For Each (
forEach
) command to your script.- On Collection, enter
${outlookConnection}
. - On Variable, enter
${emailMessageInstance}
.
- On Collection, enter
-
- Drag the Read Email (
emailRead
) command between the For Each construct. - On Message, enter
${emailMessageInstance}
. - On Subject, enter
emailMessageSubject
. - On Email Body, enter
emailMessageBody
.
- Drag the Read Email (
- Drag the Log Message (
logMessage
)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 filtered email message from your email account.
Results
You can copy this tutorial's script from the following code block:
defVar --name windowStatus --type Boolean
defVar --name outlookConnection --type EmailConnection
defVar --name keyWords --type List --innertype String --value "[testing]"
defVar --name emailMessageInstance --type EmailMessage
defVar --name emailMessageSubject --type String
defVar --name emailMessageBody --type String
waitWindow --title "Inbox - Useremail@outlook.com - Outlook" --classname rctrl_renwnd32 --processname OUTLOOK windowStatus=success
gosubIf --label openOutlook --left "${windowStatus}" --operator "Is_True" --negate
outlookConnect --mailusername "Useremail@outlook.com" outlookConnection=value
emailApplySearchFilters --searchallemails --subjectdirective "All" --inclusivesubject ${keyWords} --wordsdirective "All" --connection ${outlookConnection}
foreach --collection "${outlookConnection}" --variable "${emailMessageInstance}"
emailRead --message ${emailMessageInstance} emailMessageSubject=subject emailMessageBody=body
logMessage --message "Subject: ${emailMessageSubject}\r\n\r\nBody: ${emailMessageBody}" --type "Info"
endFor
beginSub --name openOutlook
launchWindow --executablepath "C:\\Program Files\\Microsoft Office\\root\\Office16\\OUTLOOK.EXE"
endSub