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.
cancel
Showing results for 
Search instead for 
Did you mean: 
rajnish_tiwari2
Advisor
Advisor

Introduction


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

 

Pre-requisites



  • 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



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.



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 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: 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 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 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 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 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 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 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 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 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 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 !!!

 
14 Comments
0 Kudos

i really like this post, thank you for sharing this post with us

myfiosgateway.one

mobdro

rajnish_tiwari2
Advisor
Advisor
0 Kudos
Thank You !
aditya_palekar
Advisor
Advisor
0 Kudos
Hi Rajnish,

Is it possible to add HTML scripting while designing your email template as we may want to display some table in a tabular format dynamically.

Best Regards,

Aditya
aditya_palekar
Advisor
Advisor
0 Kudos
Hi Rajnish,

Is it possible to add an HTML script into your e-mail template to render the output in a tablular format for example?

Regards,
Aditya
rajnish_tiwari2
Advisor
Advisor
0 Kudos
Hi Aditya,

Yes it is possible, as shown in the above screenshot "Workflow mail task creation" there is a dropdown "configure mail body", currently it is selected as plain text, there you can select the html text and place your HTML content., it will render it accordingly.

Thanks,

Rajnish
syenriquez
Explorer
0 Kudos

Hello i setup the same as yours and encountered and error like this:

"The login credentials given in destination 'bpmworkflowruntime_mail' are missing or incomplete. Maintain user and password in the properties 'mail.user' and 'mail.password'."

The less secure app access is no longer available

ashutosh_rambhal
Explorer
0 Kudos
Hi,

Nice and clear blog.

Is there any way to add attachment to mails from workflow?
rajnish_tiwari2
Advisor
Advisor
0 Kudos
Hi Syrahil,

 

As mentioned above in the blog that if you get the error even though entering the correct user Id and password of Gmail account, then you need to enable the option less secure app access to the Gmail account link

 

Hope it helps.

Thanks, Rajnish

 
rajnish_tiwari2
Advisor
Advisor
0 Kudos
Hi Ashutosh,

Yes we can add the attachment but the process is to have the subscription of   "Document Management service" and then configure the same as per the documentation mentioned here

Also, you can refer to the blog

 

Hope it helps.

 

Thanks, Rajnish
Saswata89
Participant
Excellent blog!

I could configure the less secure app with a app specific password configured for BTP Workflow. That's a 16 digit passcode provided by google granting access to the third party application. Great effort in keeping the nitty gritties covered in the main article.
rajnish_tiwari2
Advisor
Advisor
0 Kudos
Thanks!
Jay2
Product and Topic Expert
Product and Topic Expert
Hi rajnish.tiwari2 - Thank you for sharing this. I replicated the steps of adding in SAP Build and it works fine.
rajnish_tiwari2
Advisor
Advisor
0 Kudos
Thanks !
0 Kudos
Hi Rajnish,

 

thank you for the informations.

 

Do you know a way to send email out with link to a waiting user task?

 

In my tries the Email Task can only access before user task and hence there is no possibility to add the link to User Task.

 

BR