Skip to Content
Technical Articles
Author's profile photo Rahul Bhasin

SAP BTP Build Process Automation (RPA) integration with Gmail

SAP Build Process Automation:

SAP Build Process automation lets you to automate your business processes to meet ever changing business needs. It offers Low code no code tools which help non technical business users to automate the processes and workflows. Low code no code provides visual features to design and develop applications without even writing a single line of code.

SAP Build process automation now combines the power of workflow management, RPA , embedded AI and Machine learning capabilities.


SAP help about Process Automation:

SAP Process Automation – SAP Help Portal

Using SAP Build Process Automation


In this blog we will learn about automating a simple task which most of us do everyday, to search & read Gmail’s, download attachments to local folder.



In my Gmail, there are currently 20K emails and Gmail storage is catching up fast. So, I am trying to free up space by deleting emails which are above 1 MB in size. Before deletion, I would take the backup of these emails and download attachments if there is any.

Manual process is to filter the emails with size greater than 1 MB, print, save it as a PDF and download attachments in local folders of my desktop. But this would require lot of effort and time if it needs to be performed manually on larger volume.

So why not automate this task, where we can build a Bot which will work in background and performs the same tasks without any manual intervention.

Lets begin with Process automation.

  1. Setting up SAP BTP free tier service plans to try Build process automation service. Most likely, you need to setup a new account as I couldn’t find a way to enable this service on my existing BTP accounts. Please refer to this tutorial to setup a free tier account. 
  2. Once you received the email from SAP with the new account details and link to access it, now subscribe to SAP Build Process Automation using Boosters. Please refer to this tutorial to subscribe Build Process Automation service using Booster. (Boosters are a set of guided interactive steps that enable you to select, configure, and consume services on SAP BTP to achieve a specific technical goal.)
  3. Next step is to configure the Service account in Google Cloud platform to access Google Workspace products such as Gmail, Google Drive. Use this SAP help link to follow the steps.
  4. Lastly we need to install Desktop Agent which is required to execute the automation projects. Refer to this link to Install a Desktop agent.

So once we have performed these above steps, we are now ready to create our first project in SAP Build.

1. Access the Build process automation subscribed service from BTP account.

SAP BTP Subscriptions


2. Create a new Project from the lobby, once new project is created and design canvas is launched. Go to project properties to Add dependencies and environment variables.


Environment Variable

Also, maintain Input parameters under Input/Output in the automation details sections.

Input Parameter :

Name – size and Type – String

3. On the canvas screen add google authorization – OAUTH activity.

Google Auth task

Once the activity is added in the flow, select the activity to maintain the following properties on right side.

clientCredentialFilePath: Set as serviceaccountkeyPath from the environment variable.

Scopes -> select create Custom data

Scope list -> Select create Custom data

Scope list item – > Select create Custom data

Scope -> Select GmailScope

4. Add new task into the flow, select “Try” from the controls and place it under Authorize google task.

Select Try and maintain its properties as Errors to Catch -> GmailError

5. Add new task “Search Emails(gmail)” and place it under Try branch.

Select Search emails task and maintain its properties

Query – > “larger:” + Step0.size
IncludeSpamTrash -> false
Output Parameters -> message_ret
6. Add “Condition” task and place under search emails. Maintain the condition expression as:
7. Add “For each” task into the process flow and place under condition expression value we have maintained in above step.
Set looping list -> message_ret
8. Add  “Read Email(gmail)” task and place it under for each loop. Maintain the properties of read email step as:

message id -> Step5.currentMember.messageId

location -> filesystem
path or driveid -> local desktop folder path to store attachments
9. Finally add “Disconnect (google)” task after the For each block , as well as add it in the catch branch after Gmail error. Please check the below screenshot for the final process diagram.
10. Save the changes and final process will look like this.
Gmail Inbox filter shows 2 emails with size > 2MB.
Test the automation, enter the input parameters.
user email – email id of the inbox which needs to be scanned
Service account key – O Auth key file downloaded from google workspace

Test Run

Attachments downloaded in local folder.


In this blog, we have learnt how easy is to automate the simple processes which we perform in our daily life’s. With easily available API’s and Build platform, automating processes doesn’t require much of coding skills.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Shantanu Sharma
      Shantanu Sharma

      Rahul: Thank you for the comprehensive blog post. Is this applicable only for Google Workspace email accounts or can I use it for a personal gmail account as well? Thanks.

      Author's profile photo Rahul Bhasin
      Rahul Bhasin
      Blog Post Author

      Hi Shantanu, I have performed this test on my personal Gmail account only. You need to configure the Service account in google cloud to get access to google workspace product API's, in this case it is gmail API.

      In short, you don't need Google workspace email account and it can performed on personal gmail accounts as well.