Technical Articles
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.
Challenge:
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.
- 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.
- 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.)
- 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.
- 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.
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.
Dependency
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
message id -> Step5.currentMember.messageId



Test Run


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.
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.
Thanks