Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 
Hello bot builders !


With SAP Build Process Automation, it is quite easy to build bots to automate your processes.  But when it comes to Outlook, things might become a little complicated if you don't have a quite good understanding of how this library is designed and how it works.

This blog post (which is related to this one, and can be considered as a part of this serie) is here to help !

Unlike the previous version where you had to write the javascript code to create your bot (for all the Outlook usage, at least), SAP Build Process Automation comes with a bunch of activities that are ready to use. But first, let's see how this library works.

Overview of the library

Let's do a quick exercise. Imagine you're at home and you need to do some homework. You enter the library and here is what you see :

First thing to do : pick the books you need.

Then you sit at your desk, with a stack of books in front of you:

What's next ? You cannot read all of them at the same time so you need to pick one book from the stack to start your work.

Now, replace the word book with mail. Here is what we get :

  • Select the mails you need

  • You've got a stack of mails

  • Pick one mail to work with it

You get the idea. Outlook library works the same way : you will search for emails, and then you will work with what we call the Context Current Email (also known as CCE). Don't forget this name, as it will be used later in this blog post.

Again, you cannot have multiple Context Current Emails, just like you cannot read multiple books at the same time : you read one book (even partially) then you pick another book and start reading.



First thing to do when you want to work with Outlook in an automation : add a dependency to Oulook library !

Open the settings of your project, and simply add the Outlook library (see below) :

Ok so now we can start working with Outlook. Using the library analogy, to be able to read some books, we must enter the library: that's why we always use the activity Open Outlook instance before using any other Outlook activity.

And when we are done, we leave the library : we use the Release Outlook instance activity. So we get the below structure :

Ok and now ?


How to select the CCE ?

To select the mails, we use the Search Email activity : it's the first activity in the category [irpa_outlook] Email so you cannot forget to use it !

Moreover, this activity is quite easy to use ! When you edit its properties, you have a popup where all you need to do is select what you need to search (and also in which folder, etc.) :

Note : searchCriteriasList is... a list ! So you can add as many criteria as you wish.


This Search Mail activity kind of returns a list of mail matching the criteria. It represents the stack of books.

Warning : the Search Mail activity does not exactly return a list that you can save in some variable. The result is stored internally and all the activities will work with this "hidden" result.
Wait... We have a list but we can only work with one item at a time ?

Yes ! And here is how we can do it.


Work with one email at a time

To work with these mails, we need to insert a loop in our automation. For each iteration, we make sure that the CCE exists (at the beginning of the loop) and we move to the next item in the list (at the end of the loop).

A picture is worth a thousand words :

Let's detail this piece of automation :

  1. We enter the library

  2. We search for some mails, depending the criteria we set

  3. Using this loop we will be able to work with all the found mails

  4. We need to make sure the CCE exists, using the Is Context Current Email Not Exist activity

  5. We test the result of the previous instruction. If true, let's get out from the loop

  6. Otherwise we go to the default branch

  7. Here we can do whatever we want with the CCE (get the subject, get the recipients, get the attachments, etc.)

  8. Once we're done with this CCE, let's take the next item in the list and loop

  9. We leave the library

In Step 7, do NOT use the Delete Email activities, because they change the Context collection. If you want to delete multiple emails, please have a look at the documentation.


There are similar activities which are available to check that the CCE exists. Make sure you're using Is Context Current Email Not Exist in that case.


Note : all the activities you can use when the CCE exists are available under the categories emailItem and properties


And now ?

Now it's up to you to build automations where you can work with tons of mails. For example you can get all the POs you received, and for each one of them, download the attached files and process the PO in S4 !

As you could see, there was no need to write a single line of code, and that's why working with Outlook has never been so easy !

Note : you can also have a look here to learn the best practices about Oulook on our Help portal.


Find more information on SAP Build Process Automation :

Exchange knowledge: SAP Community | Q&A | Blog

Learn more: Webinars | Help Portal | openSAP

Explore: Product Information | Successful Use Cases

Try SAP Intelligent RPA for Free: Trial Version | Pre-built Bots

Follow us on: LinkedInTwitter and YouTube