cancel
Showing results for 
Search instead for 
Did you mean: 

Mail Attachment Name

Former Member
0 Kudos

Hi,

I am using File to Mail scenario. There is no mapping, it uses dummy Interfaces. I have Adapter Module at the Receiver in Mail to dynamically get the filename and set it as the attachment name.

Following is the module code. The problem with the code is I get 2 attachments in the mail, One with proper file name as desired and the 2nd attachment as "Untitled.xml". Need to get rid of this Untitled.xml. Note: Keep attachments is Checked as I need the file in attachment.

**********************************************************************************************************

Message msg = (Message) inputModuleData.getPrincipalData();

XMLPayload xmlpayload = msg.getDocument();

String strfileName = msg.getMessageProperty("http://sap.com/xi/XI/System/File", "FileName");

byte by[] = xmlpayload.getText().getBytes();

xmlpayload.setName(strfileName);

xmlpayload.setContentType("text/xml");

xmlpayload.setContent(by);

msg.addAttachment(xmlpayload);

inputModuleData.setPrincipalData(msg);

Accepted Solutions (0)

Answers (5)

Answers (5)

sunil_singh13
Active Contributor
0 Kudos

Hi Sunayna,

First of all i wold say you don't use adapter module to achive your requirment.

Better to go for Java mapping whereever you are converting File structure to mail structure.

Simple coding using X-path will resolve your problem. and the attchment sent will not contain untitled.xml

If you still want to use Module then try to delete the attachment with name untitled.xml.

you can refer iterator part of https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=64389779

code to fulfill your requirment. in this part of code it is shown how to get list of attachment and subsequently how to operate on that.

Thanks,

Sunil Singh

Former Member
0 Kudos

Sunil,

The attachment "untitled.xml" seems to be not accessible and gives Null Pointer exception.

thanks..

sunil_singh13
Active Contributor
0 Kudos

Hi Sunayna,

Put Traces in your modul code and see if you are able to see Untile.xml name in the trace.

It has to be somewhere. You have to look for that.

Have you thought abt doing this in using java mapping . If you need then i can send you the code for doing it in Java mapping.

Thanks

Sunil Singh

Former Member
0 Kudos

Create an UDF and mention the key and the value of the file name you wish

public void DynamicFilename(String[] a,String[] b,ResultList result,Container container){

//write your code here

AbstractTrace trace = container.getTrace();

String strDirectory=" ";

String strFileName="";

try

{

Map map= container.getTransformationParameters();

//This is for generating the file Direcotry Dynamically

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get

(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/File", "Directory");

DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File",

"FileName");

strDirectory= "/xxx/xxx/xx";

strFileName= b[0] + b[2] + b[1]+ ".XML";

trace.addWarning("strDirectory " +strFileName);

conf.put(key, strDirectory);

conf.put(key1, strFileName);

result.addValue(b[0]);

}

catch(Exception ex)

{

trace.addWarning("Catch Block " );

}

Edited by: Sainath Chutke on Jan 16, 2009 10:19 AM

Former Member
0 Kudos

Sainath,

I do not use any mapping between File & Mail. The scenario uses dummy Interfaces.

thanks.

Former Member
0 Kudos

Stefan,

I tried adding setName, it seems to not work here. As I still get 'Untitled.txt' as attachment.

thanks..

Shabarish_Nair
Active Contributor
0 Kudos

>

I am using File to Mail scenario. There is no mapping, it uses dummy Interfaces. I have Adapter Module at the Receiver in Mail to dynamically get the filename and set it as the attachment name.

in case you want to change the name of the Main payload (i guess that is what comes as the untitled.xml)

use the following code;

TextPayload txtpayload = message.getDocument();

txtpayload.setName("WHAT_EVER_YOU_WANT");

Former Member
0 Kudos

Shabarish,

The output i get after using TextPayload is Just "Untitled.xml".

thanks..

stefan_grube
Active Contributor
0 Kudos

Sure, with this code you copy the payload to the attachment, so your mail has two parts.

Try this code:

https://www.sdn.sap.com/irj/scn/wiki?path=/display/xi/adapterModulePI7.0SetAttachmentName

Former Member
0 Kudos

Stefan,

The code in the link gives the output as "Untitled.txt".

thanks

stefan_grube
Active Contributor
0 Kudos

Could you use the same code and add:

payload.setName(fileName);

Former Member
0 Kudos

Hi,

Please Refer this blog:

/people/prasad.ulagappan2/blog/2005/06/07/mail-adapter-scenarios-150-sap-exchange-infrastructure

Cheers

Sunil.