Skip to Content

Receiver mail adapter with dynamic mail ID

Nov 02, 2017 at 08:32 AM


avatar image

We have a requirement,We need to get the mail ID from the payload and send it to that particular mail ID. We are using file to Mail scenario and message should be sent as an attachment.

Mail ID is different in each message.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Raghuraman S Nov 02, 2017 at 09:22 AM
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Will this work without any extra setups? will the adapter take email ID directly from the payload?

Priyanka Anagani Nov 03, 2017 at 07:55 AM

Hi Bharat,

Can you provide more details about the requirement. There are different points we need to consider while handling this scenario. I've worked on couple of similar requirements and I would suggest finalizing the requirement before deciding on the approach.

You mentioned that source file has to be sent as an attachment. Is it an XML/Text attachment?

Do you need mail body & attachment or only attachment? - If you need both body & attachment, there are 2 approaches. One is using mailpackage and other is java mapping. SAP recommends to use java mapping instead of mail package.

If you are not comfortable with java mapping, you can still continue using mail package.

What should be the attachment name? Is it static or dynamic like source file name has to be attachment name etc.?

any other requirements like email subject etc.?

Provide the complete requirement so that I can help you in achieving it.


Show 4 Share
10 |10000 characters needed characters left characters exceeded

Hi Priyanka,

We will be sending the data as only attachment, the attachment is a text file.

Also we need dynamic name for the attachment.


As the source & attachment is a text file and the mail recipients are in the payload, you need to use content conversion and mapping. Below is the approach I can think of to avoid javamapping & use Mail package.

1. In the File sender channel, do the content conversion and also enable Adapter Specific Message Attributes to read source file name.

2. Create a simple 1:1 message mapping with same structure on both source & target side. Only thing is, while map the target room with a UDF.

3. In the UDF, use dynamic configuration, read the source file name & write it to mail header say "XHeaderName1". Also set the email email recipient. Below is the sample code.

String emailTo = "";
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey emailToAdd = DynamicConfigurationKey.create("","THeaderTO" );
conf.put(emailToAdd, emailTo);

Also refer below links to set attachment name.

4. In Mail receiver channel,

  • uncheck UseMailPackage
  • check Keep attachments
  • select Adapter Specific Message Attributes & Variable transport binding. Referring the above link.
  • In the module tab, before the Mail Adapter Bean, use MessageTransformationBeam to convert the target XML payload back to Text File.



Hi Priyanka ,

Thanks for your answer.

I have tried with the above code for setting the email ID dynamically , Im getting below error.

Runtime exception when processing target-field mapping /ns0:MT_Desadv1_ToMail_Target//ns0:MT_Desadv1_ToMail_Target/*Email_TO; root message: Exception:[java.lang.NullPointerException: while trying to invoke the method, java.lang.String) of a null object loaded from a local variable at slot 4] in class method calculate[,] See error logs for details

Please give me the complete code so that I will get to know where I'm doing wrong,Im basically new to UDFs


I have used the above code and I have given the mail address as dummy, When I pass the actual mail ID to which we have to send the file in the payload.

I am getting this error

Transmitting the message to endpoint using connection File_http:// failed, due to: Failed to call the endpoint [null "null"]; nested exception caused by: server not responding OK to RCPT TO; 501 Syntax error - Badly formatted address