Workflow modelling of Mail Task in SAP Business Application Studio : GMAIL

In this blog, we are going to discuss the modeling of workflow’s mail task, While I was looking for an approach to send mail to the Gmail account of the end-user, While I was implementing the mail task, We found that there is no such example available to configure the mail task, which can send mail to Gmail account, However, the SAP’s documentation is quite good which explained the SMTP setup for both Gmail and outlook servers. But when we have some kind of examples, It helps us to implement the use case according to our requirements more effectively. So In this blog, I am going to cover the workflow modeling of Mail Task and configuration of properties of Mail Tasks. SAP Business Application Studio’s setup and basic workflow modelling are part of this blog I am not going to explain the roles and dev spaces creation of SAP Business Application Studio as well as the creation of basic workflow module in SAP Business Application Studio editor, To know more details, find below the links,

Overview of SAP Business Application Studio

SAP Business Application Studio’s Configuration

Working with SAP Business Application Studio

  • SAP Business Technology platform(BTP) account with cloud foundry enablement in Trail Account.
  • Entitlements for Portal, Workflow, Application Runtime, and Application Studio
  • Workflow service configuration with FLP configuration, which can be done by the latest offering of BTP as mentioned below

Configuration of Workflow Service Steps

  • Navigate to your trial account,
  • Click on the Booster icon as shown below in Figure-1

Workflow%20Booster%20Icon%20selection

Figure-1: Workflow Booster Icon selection

  • After clicking on Booster Icon, as shown above, a new tile would be visible and, click on the start icon to configure the workflow service, myInbox app, Workflow instance, workflow definition, and roles configuration.

Process%20to%20automate%20the%20workflow%20configuration

Figure-2: Process to automate the workflow configuration

Dev Space creation in SAP Business Application Studio

Once the subscription of SAP Business application is done, launch the IDE and create the dev space as shown in Figure-3, by selecting the Workflow management from the Additional extensions section, the creation of roles is done automatically and it part of Booster app execution

Dev%20space%20Creation%20Process

Dev space Creation Process

Multi-target Application (MTA) project creation process

  • After the dev space creation, as it might take a time to create the space, if you are doing it for the 1st time, then you need to open a new workspace. Select the “projects” folder and proceed.
  • Now In the workspace, from the File menu select the “New Project from Template” > click on Basic Multitargeted Application > START > Enter Project Name as “myMailTask”> click on Finish as shown below

Figure-4%3A%20MTA%20Project%20Creation

Figure-4: MTA Project Creation

  • After this step, we get a message at the right bottom corner that project generation is successful and in the left panel you can find the two additional files such as  .gitignore, mta.yaml will be generated as shown below

Generated%20MTA%20project%20overview

Generated MTA project overview

Workflow module and mail task creation

Now let’s follow the steps to create a workflow module

  • Navigate to terminal from menu and select new terminal and navigate to the terminal.
  • cd myMailtask
  • type yo
  • select “workflow/workflow Module” template
  • Enter the path of mta.yml, in my case Since I’ve already at the folder path  where mta.yaml is present, hence just press enter
  • Enter the workflow name as shown below

Workflow%20module%20generation%20process

Workflow module generation process

  • Now navigate to the workflow editor, select the task type, here we will select the mail task,
  • Now, drag and drop the mail task between start and end event.
  • Navigate to the left and click on the Details tab as shown below
  • Now enter the email Id, whom you want to send a mail with the information when you trigger the mail task from workflow instance.
  • Enter Subjet line like: “SAP Workflow mail service”
  • Enter the text Body as shown below
  • Select the configure mail body as “Plain Text”, You have the option to create an HTML-based mail body but in that case, you need to create a file and enter the info in that file.(which we are not doing currently, just proceeding with plain text)
  • Save the file.

Workflow%20Email%20task%20creation

Workflow mail task creation

Configuration of SAP BTP Destination for mail task

To send the mail to the configured user, you need to configure the destination in BTP cockpit.

  • Login to BTP cockpit and open the subaccount where you have an Administrator role, click on the destination tab in the left panel, create a destination and provide the information as shown below

Mail%20Task%20Destination%u2019s%20Configuration

Mail Task Destination’s Configuration

  1.  Click on the destination tab
  2.  Click on the New Destination tab and provide the information as mentioned.
  3.  Provide the name “bpmworkflowruntime_mail” as this destination name is constant.
  4. Type should be selected as MAIL
  5. Provide the Gmail User Id and password, which you basically used to log in to your Gmail account.
  6. Provide the Additional Properties as per the detail mentioned in the documentation link
mail.smtp.auth true
mail.transport.protocol smtp
mail.smtp.starttls.required true
mail.smtp.ssl.checkserveridentity true
mail.smtp.host smtp.gmail.com
mail.smtp.port 587
    Additional properties

Workflow Build and Deployment

Once the workflow modeling of mail task is done, you need to build and deploy the workflow

  • Navigate to your workflow project folder, open the yaml file and check the service plan, if it is lite that means it is a trial account else standard for a paid subscription, right-click on the mta.yaml file and select “Build MTA Project” as shown below

MTA%20Build%20of%20workflow%20module

MTA Build of workflow module

  • Once the steps are executed, generates a mta_archives folder, expand the folder and you will find the <project_name>.mtar file, > select > right-click on the *.mtar file > click on “Deploy MTA Archive” as shown below

Deployment%20of%20MTA%20Archive

Deployment of MTA Archive

  • If you are deploying for the 1st time then it will ask for the cloud foundry endpoints of mentioned sub-account. (check the sub-account to find the CF endpoint)
  • Enter the SAP BTP email-Id and Password after entering the CF endpoints.
  • Once deployment is successful, Now we need to test, if the email task is working or not?

Workflow Instance Creation

Once the deployment of workflow is completed, Now create the workflow instance.

  • Navigate to the SAP BTP cockpit of your trial account.
  • From the Navigation section, select the Instance, click on it, and scroll down to the subscriptions (2) section as shown below
  • click on the link next to Workflow management

Workflow%20Management%20Launch

Workflow Management Launch

  • After the launch of workflow Management in a new browser tab, click on the Monitor workflow(Workflow Definitions)
  • Search for myMail Workflow as shown below and click on “Start New Instance
  • A popup would open and provide an empty {} as we are not providing any input value.
  • Click on the button as shown below on “Start New Instance and close

Workflow%20Instance%20creation%20process

Workflow Instance creation process

  • Now to monitor, if created workflow instance was executed successfully, Navigate back
  • Click on the Monitor Workflow(Workflow Instance) tiles and check if the instances were executed successfully or not? if it failed due to below reason

“The server ‘smtp.gmail.com’ could be reached, but the login with the given credentials failed. Verify that the credentials are valid for the server.”

  • Then enable the less secure option from the given link of your Gmail account as we are testing the workflow instance to the send to Gmail.
  • Once the instance was executed successfully, The mail would be triggered and the configured email address would receive the mail in the Inbox as shown below

Gmail%20mail%20Snapshot

Gmail mail Snapshot

Conclusion

The main purpose of this blog is to show how mail tasks can be configured, deployed and triggered mail task in the SAP Workflow management service, Also the document is quite good but sometimes we need to have reference to implement the feature, while automating the task. So I have shown the approach to send a mail using SAP Workflow services to the Gmail account.

Suggestions and feedback are welcome !!!