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.

Important:starting from IBM RPA 23.0.10, this command is deprecated. Use the Connect to Microsoft Outlook command instead.

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

  1. Log in to IBM RPA Studio.
  2. 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.

  1. 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.
  2. Place your mouse cursor on the Outlook panel and hold the Ctrl + Shift key on your keyboard until the panel is highlighted in green.
  3. On the recorder bar, click Window > Wait for window to appear.
  4. The Wait for Window to appear (waitWindow) opens. Notice how some parameters are already filled.
    1. On Success, enter windowStatus and click Save.
  5. Click Home > New Routine.
  6. On Name, enter openOutlook and click Save.
  7. Drag the Launch and Attach Window (launchWindow)command to your script.
    1. 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.
    2. Click Save.
  8. In the script's main routine, drag the Run Subroutine if (gosubIf) command.
    1. On Name, select openOutlook.
    2. On Left Operand, enter ${windowStatus}.
    3. On Operator, select Is true.
    4. Enable Negate.

Connecting to Outlook Server

  1. Drag the Connect to Outlook Server (outlookConnect) command to your script.
    1. On Email, enter the email that is connected to the Outlook application.
    2. On Connection, enter outlookConnection and click Save.

Filtering emails

  1. Create a new variable called keyWords of type List<Text>, add words that you want to filter for. In this tutorial, the word is testing.
  2. Drag the Apply Search Filters (emailApplySearchFilters) command to your script.
    1. On Connection, enter ${outlookConnection}.
    2. Enable Search all Folders.
    3. On Inclusive Words in the Subject, enter ${keyWords} and click Save.

Reading and logging the contents of filtered emails

  1. Create a new variable called emailMessageInstance of type Email Message.
  2. Drag the For Each (forEach) command to your script.
    1. On Collection, enter ${outlookConnection}.
    2. On Variable, enter ${emailMessageInstance}.
    1. Drag the Read Email (emailRead) command between the For Each construct.
    2. On Message, enter ${emailMessageInstance}.
    3. On Subject, enter emailMessageSubject.
    4. On Email Body, enter emailMessageBody.
  3. 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:

Tutorial_image_1

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