Skip to Content
avatar image
Former Member

Mail Attachment Name

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);

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • avatar image
    Former Member
    Jan 16, 2009 at 08:45 AM

    Hi,

    Please Refer this blog:

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

    Cheers

    Sunil.

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 16, 2009 at 08:47 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 16, 2009 at 08:49 AM

    >

    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");

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 16, 2009 at 09:19 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 16, 2009 at 11:26 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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