cancel
Showing results for 
Search instead for 
Did you mean: 

Receiver mail adapter with dynamic mail ID

Former Member
0 Kudos

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.

Accepted Solutions (0)

Answers (2)

Answers (2)

PriyankaAnagani
Active Contributor
0 Kudos

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.

https://blogs.sap.com/2016/03/10/stop-using-mail-package-simplify-your-mail-receiver-adapter-scenari...

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.

--Priyanka

Former Member
0 Kudos

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.

PriyankaAnagani
Active Contributor

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 = "abc@xyz.com";
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey emailToAdd = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/Mail","THeaderTO" );
conf.put(emailToAdd, emailTo);

Also refer below links to set attachment name.

https://archive.sap.com/discussions/thread/3912824

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.

--Priyanka

Former Member
0 Kudos

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 com.sap.aii.mapping.api.DynamicConfiguration.put(com.sap.aii.mapping.api.DynamicConfigurationKey, java.lang.String) of a null object loaded from a local variable at slot 4] in class com.sap.xi.tf._MM_Desadv1_ToMail_ method calculate[bharath@gmail.com, com.sap.aii.mappingtool.tf7.rt.Context@26af720d] 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

Former Member
0 Kudos

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 <local> using connection File_http://sap.com/xi/XI/System failed, due to: com.sap.engine.interfaces.messaging.api.exception.MessagingException: com.sap.aii.af.sdk.xi.srt.BubbleException: Failed to call the endpoint [null "null"]; nested exception caused by: java.io.IOException: server not responding OK to RCPT TO; 501 Syntax error - Badly formatted address

former_member186851
Active Contributor
0 Kudos
Former Member
0 Kudos

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