on 03-10-2015 2:58 PM
Hi Folks,
I am using SAP PI 7.30 wherein I am creating a Proxy to Mail interface. The data from the proxy needs to be converted into .csv file and to be sent as an attachment in email. Also the file name is to be dynamic which is Companyname_Datestamp.csv. I am facing the issue with the filename.
I have converted the XML content of proxy to flat file content using Message transformer bean module in receiver mail adapter.
I have written the UDF to generate the file name: The UDF is as below:
MappingTrace setAttachmentName_trc;
setAttachmentName_trc = container.getTrace();
String mailHeaderValue = "";
DynamicConfiguration conf = (DynamicConfiguration) container
.getTransformationParameters().get(
StreamTransformationConstants.DYNAMIC_CONFIGURATION);
// try to create a key
try {
DynamicConfigurationKey keyM1 = DynamicConfigurationKey.create(
"http:/" + "/sap.com/xi/XI/System/Mail", "XHeaderName1");
mailHeaderValue = "attachment; filename=" + fileName;
conf.put(keyM1, mailHeaderValue);
} catch (Exception e) {
setAttachmentName_trc.addWarning("caught exception: " + e
+ " - probably no adapter-specific message attribute.");
e.printStackTrace();
}
return mailHeaderValue;
I am passing a dynamic filename over here as input which changes everyday as date changes. Also I have checked the ASMA properties and Variable Trsnport Binding in receiver mail adapter. The value set for XHeaderName1 is Content-Disposition. But still the name of the file in the attachement is always "Untitled.txt".
Also find the attached Mail receiver adapter screenshot, Dynamic config screenshot of sxmb_moni and UDF code.
Please assist.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes Monika. ASMA variable can't change mail attachment name. MIME contentType need to be updated in Message Mapping OR in Adapter Engine (using module).
1) Create a simple UDF, container.getOutputHeader().setContentType("text/plain;charset = \"UTF-8\";" + "name=\"" + FileName + "\"");. Follow
OR
2) Use MessageTransformBean (not dynamic)
FYI..more info
Hi Monika,
The Dynamic Configuration Key's should be mentioned as 'Variable Header' at Receiver Mail Channel.
Check my screen shot:
You could have used 'XHeaderName1' KEY which you created in the UDF. 'Content-Disposition' we use as Module Key. Like I am not using "Use Mail Package" option and populating Dynamic Subject (THeaderSubject), Recipients(THeaderTO) and Sender(THeaderFrom) fields in UDF.
For Dynamic Filename as mentioned by Raghu, follow below blog:
Regards,
Nabendu.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nabendu,
I understand your point that setting filename is not possible using ASMA-Variable transport binding concept. Then how would we be able to set the attachment filename.
The above link is not helping me.
Also when I give THeaderSUBJECT in the XHeaderName1 of transport binding to set dynamic test through a UDF, it does not give any subject and my email appears without subject.
Below is the UDF:
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
// try to create a key
DynamicConfigurationKey keyM1 = DynamicConfigurationKey.create(
"http:/" + "/sap.com/xi/XI/System/Mail", "XHeaderName1");
String mailHeaderValue = "Info Armor file for " + Date;
conf.put(keyM1, mailHeaderValue);
return mailHeaderValue;
Kindly suggest.
Hi Monika,
Please find the below screen shots:
UDF: Create Key as name "THeaderSUBJECT". <accessKey> is a variable passed from Sender message. You can use any Constant also. You can use this UDF in between any field to field mappings because UDF is not working on any Target field. I have used somewhere 1:1 mapping. Just Returned back same Sender Value to the Target.
Use the Same Name as Variable Header in your Communication Channel ("THeaderSUBJECT")
Regards,
Nabendu.
Hi Monika,
The body or the mail content does not come under Header Fields (ASMA).
Configuring the Receiver Mail Adapter - Advanced Adapter Engine - SAP Library
Most likely you need to use Mail Package option.
Regards,
Nabendu.
Monika,
Please try this approach. Modify html body in mapping.
User | Count |
---|---|
87 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.