Skip to Content
Technical Articles
Author's profile photo Soura Gopal Sethy

Dynamically send email based upon different environment (DEV/QA/PROD)


This blog helps you to solve the most common requirement to send the Email to diffrent list of recipients based on the different environments of SAP Cloud Platform Integration Tenant’s (eg-Dev,Prod,Qa).


Current Scenario:

In this scenario we are storing the Tenant URL and Email IDs of the recipients for different environment (prod,dev,test) in a single value mapping as shown below.

Why we are doing so?

To give us the flexibility to send Email (as per requirement) from different Cloud Platform Integration (CPI) Tenant as we move our iFlow from one enviroment to another.

STEP 1: Creating a Value Mapping to store the URLs and Email IDs.

STEP 2: Using a Groovy Script in your iFlow to use the Value Mapping.

I-Flow Explanation:

  • We are using a HTTP to triger the Integration flow here,You can use process direct as well for your custom requirment.
  • Then using a “Groovy Script” to envoke the Value Mapping.
  • Now you can accces the header (set inside groovy) in the Mail adapter’s “To” field using the apache camel expression

Groovy Script:

import java.util.HashMap;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.HashMap;
import groovy.xml.*;

def Message processData(Message message) {

    def baseUrl = "${message.getHeaders().get('CamelHttpUrl')}".toString()
    def Environment="";
     def valueMapApi = ITApiFactory.getApi(ValueMappingApi.class, null);
    def DEVURL = valueMapApi.getMappedValue('SKEY', 'SIDENTIFIER', "DEVURL", 'TKEY', 'TIDENTIFIER');
    def PRODURL = valueMapApi.getMappedValue('SKEY', 'SIDENTIFIER', "PRODURL", 'TKEY', 'TIDENTIFIER');
    def TESTURL = valueMapApi.getMappedValue('SKEY', 'SIDENTIFIER', "TESTURL", 'TKEY', 'TIDENTIFIER');
    else if(baseUrl.contains(TESTURL))
    else {

     //Set mail recipient
       def mailDl = valueMapApi.getMappedValue('SKEY', 'SIDENTIFIER', Environment, 'TKEY', 'TIDENTIFIER');
        message.setHeader("Mail_DL",mailDl )
        message.setHeader("ENV", Environment)
    return message;


Groovy Script Explanation:

  • First, we are fetching all the tenant env. URLs using value mapping API. We are then storing this in different variables: DEVURL,TESTURL and PRODURL.
  • Using Camel Http we are fetching the base Url of the tenant from the header.
  • Now, we are comparing the tenant base url with variables (from earlier) to figure out the current environment.
  • Based on the current environment we are fetching the Email recipients ID from ValueMapping by using ValueMappingAPI.
  • Now, we are setting Mail ID in header dynamically.


So, to conclude this blog helps to send Email to different recipients based on the development tenants of SAP Clould Platform Integration(CPI).

If you have any queries, please feel free to ask your question in comments. I would request everyone to provide your feedback and like if this blog post finds helpful for you.


Thanks & Regards,


Assigned Tags

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

      A good and informative blog Soura. Thanks for sharing.

      Author's profile photo Samarjit Singha
      Samarjit Singha

      This is a very useful blog, it simplifies sending mail dynamically (no need to open the CPI artifact repeatedly to make changes, it can be accessed from value mapping).