cancel
Showing results for 
Search instead for 
Did you mean: 

Receiver Mail Adapter attachment file name issue

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

RaghuVamseedhar
Active Contributor
0 Kudos

Monika,

Please set MIME contentType in UDF.

container.getOutputHeader().setContentType("text/plain;charset = \"UTF-8\";" + "name=\"" + FileName + "\"")

Former Member
0 Kudos

Hi Raghu,

Kindly suggest what UDF to use.

Also it is clear to me that ASMA-Variable transport binding will not help to change the filename.

Kindly suggest the alternative approach.

RaghuVamseedhar
Active Contributor
0 Kudos

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

Former Member
0 Kudos

HI Raghu,

Thanks for the reply.

Can you please also help me to get the body of the email without using mail package like

Hi John,

Please find the attachment.

Answers (1)

Answers (1)

nabendu_sen
Active Contributor
0 Kudos

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.



Former Member
0 Kudos

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.

nabendu_sen
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

Hi Nabendu,

I am able to get the dynamic subject. The client requirement is also to get the body like "Please find the above attachment".

How to achieve it without using mail package.

nabendu_sen
Active Contributor
0 Kudos

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.

RaghuVamseedhar
Active Contributor
0 Kudos

Monika,

Please try this approach. Modify html body in mapping.

html content and .txt attachment in the email