Skip to Content
Technical Articles
Author's profile photo Samir HAMICHI

Combining Outlook rules with SAP Intelligent Robotic Process Automation to process emails

1. Introduction

 

My name is Samir Hamichi, I’m part of the SAP Intelligent Robotic Process Automation Customer Adoption Team.

In a series of blog posts, I want to give some best practices from the development perspective. I will focus on the Low Code/No code approach.

This blog post, as a use case of low code, I’ll take emails processing scenario, showing you how to combine Outlook rules that sort your emails in specific folders with few lines of code as a bot that allows you to process massive emails related to a specific process.

2. Context and steps

Let’s assume Funds processing emails. You receive regularly emails asking you to buy or sell shares.

  • Inside the outlook inbox, you have probably set a rule filtering these emails into a specific folder called: __Funds processing
  • You read each email, process the request and then move it to a sub-folder called: processed

As a quick solution, follow the steps below.

Step 1: Outlook settings

  • Create the ‘__Funds processing’ folder in your outlook inbox.
  • Create the ‘Processed’ folder as a sub-folder of ‘__Funds processing’
  • Create some fake emails for testing
  • Setup and apply a rule filtering the emails with subject containing ‘Funds processing’ text in the subject

 

    • Right-click on one of the received emails and click on Create Rule

    • Check Subject contains
    • Add a condition on Subject contains: Funds processing
    • Check Move the item to folder 
    • Click Select Folder

 

    • Select the folder __Funds processing
    • Click OK

    • Click OK to confirm the rule

    • Check Run this rule now on messages already in the current folder
    • Click OK

The rule is created and applied to the emails received for Funds processing.

 

Step 2: Create a Workflow

Note that I’ve created a project and I use ErrorTimeoutMgt as project name. I will use this use case in a coming Blog post dedicated for Errors and timeouts handling. If you wish, you can customize a different name when you create your project.

Now, after creating the project, we need to create a workflow with one custom step:

 

Step 3: Include Outlook Library

Step 4: Edit generated script

On the Scripts panel, double-click on the FundsProcessing script. This will display the script as below. The custom step highlighted has to be customized.

 

Step 5: Add custom code

Customize the code of the step as below:

  • add the code from ctx.outlook.init();  to ctx.outlook.end();
  • replace your.email@domaine.com with your email
GLOBAL.step({ Custom: function(ev, sc, st) {
	var rootData = sc.data;
	ctx.workflow('FundsProcessing', 'c4d5018b-67cc-47b5-a135-c9a62df79773') ;
	// Custom
	ctx.outlook.init();
 	var processedFolder = ctx.outlook.folder.getFolder({folderPath : '\\\\your.email@domaine.com\\Inbox\\__Funds processing\\Processed'});
	var folder = ctx.outlook.folder.getFolder({folderPath : '\\\\your.email@domaine.com\\Inbox\\__Funds processing'});
	var nbMails = folder.Items.Count;	
	ctx.log(nbMails);
	for (var i =1; i <=nbMails; i++){
		var data = folder.Items.Item(1); 
		ctx.log('##############################################################');
		ctx.log('################################################ email n°:'+i);
		ctx.log("email : "+data);
		ctx.log("email.SentOnBehalfOfName : "+data.SentOnBehalfOfName);
		ctx.log("email.SentOn : "+data.SentOn);
		ctx.log("email.SenderName : "+data.SenderName);
		ctx.log("email.To : "+data.To);
		ctx.log("email.ReceivedTime : "+data.ReceivedTime);
		ctx.log("email.Body : "+data.Body);
		data.UnRead = false;
		data.Move(processedFolder);
	}
	ctx.outlook.end();
			
	sc.endStep(); // end Scenario
	return;
}});

 

Step 6: Run and test the scenario

  • Run your project in a Debug mode (F5).
  • From the systray, test your scenario by choosing: Test FundsProcessing

you will see the output in the Events panel of the debugger:

 

If you take a closer look into the code, instead of logging the emails into the events viewer, you can add relevant code or give the data as input to a separate scenario that leverages the content of each email, including attachments.

If you want more features about Outlook, like searching emails instead of using rules, check the different blog posts related to the topic here Enhance your bot building with templates.

 

3. Conclusion

In this blog post, I presented a simple use case combining Outlook rules with SAP intelligent Robotic Process Automation. The rules route emails related to a certain business process (Funds processing) to a specific folder. The bot, when triggered, reads the emails from the folder, process them and classify them as processed in a dedicated folder.

With few lines of code, we I was able to process emails of a my business process. You may think for the replication of this combination of Outlook rules/SAP Intelligent Robotic Process Automation Bot as a template to apply it for many other processes.

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Suvendu Banerjee
      Suvendu Banerjee

      Hi Samir,

      Very nicely explained indeed. Thanks so much. Can you please tell me how to get the MessageID of a particular email using your piece of code.

      For example, you have used ctx.log("email.SenderName : "+data.SenderName);

      I tried using ctx.log("email.MessageId: "+data.MessageId);

      But it is not returning anything.

      Appreciate your help.

      Thanks. Take care.