cancel
Showing results for 
Search instead for 
Did you mean: 

Send emails dynamically in SAP CPI

Israel_Mata1001
Explorer
0 Kudos
356

Good afternoon!

Currently I am working on sending emails to multiple recipients using an XML payload defined as follows:

<EmpRecords>
     <EmpRecord>
           <EmpId>123</EmpId>
           <EmpFName>Gopi</EmpFName>
           <EmpLName>K</EmpLName>
           <EmpCountry>IN</EmpCountry>
           <EmpSalary>30000 </EmpSalary>
           <email>test1@mail.com</email>
     </EmpRecord>
     <EmpRecord>
           <EmpId>456</EmpId>
           <EmpFName>Ram</EmpFName>
           <EmpLName>C</EmpLName>
           <EmpCountry>IN</EmpCountry>
           <EmpSalary>30000</EmpSalary>
           <email> test2@mail.com </email>
     </EmpRecord>
     <EmpRecord>
           <EmpId>789</EmpId>
           <EmpFName>Mohammad</EmpFName>
           <EmpLName>Khan</EmpLName>
           <EmpCountry>IN</EmpCountry>
           <EmpSalary>40000</EmpSalary>
           <email> test3@mail.com </email>
     </EmpRecord>
      <EmpRecord>
           <EmpId>234</EmpId>
           <EmpFName>Varnikai</EmpFName>
           <EmpLName>L</EmpLName>
           <EmpCountry>IN</EmpCountry>
            <EmpSalary>40000</EmpSalary>
           <email> test4@mail.com </email>
     </EmpRecord>
</EmpRecords>

The test emails are:

test1@mail.com

test2@mail.com

test3@mail.com

test4@mail.com

However, I have not found a way to put the 4 emails coming from the payload into the email connector definition.

Mario_Sanchez10_0-1725905676805.png

 

Is there a method to dynamically place emails that come from an XML Payload?

Thanks

Regards

View Entire Topic
nageshrao
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Mario, 

To configure multiple email receivers we must pass all the email addresses separated by a comma (,) to the "To" field of the receiver mail adapter. 

Reference - Configure the mail receiver adapter 

nageshrao_0-1725920683684.png

Now assuming you have to send the same email content to all the possible email IDs that are present in the source XML payload, we would need to dynamically extract the email IDs, have them comma (,) separated and pass the value to the receiver Email Adapter's "To" field. 

Step 1 - Extract all possible receiver email addresses separated by comma (,) into a property.

To achieve this you can use a content modifier and extract the IDs using an xpath expression into a property -  - 
Property Name = receiverEmailID
Source Type = XPath
Source Value = string-join(//email/normalize-space(), ',')

nageshrao_1-1725921049034.png

For your XML payload, above step would update the property receiverEmailID with value - test1@mail.com,test2@mail.com,test3@mail.com,test4@mail.com

Step 2 - Configure the property value ${property.receiverEmailID} in the "To" field under processing for mail receiver adapter.

nageshrao_2-1725921380970.png

 

 

Israel_Mata1001
Explorer
0 Kudos
Thanks for the Information, this resolved my problem.