cancel
Showing results for 
Search instead for 
Did you mean: 

Reciver Mail adapter same file name attachement issue

Former Member
0 Kudos

Hi All,

I have a requirement SFTP ----> Mail Attachment with same file with date (filename_YYYYMMDD)

I am trying to take file name from Dynamic configuration from sender and trying to put ContentType in Header output.  But still not working..

How to set content type payload body?  Kindly provide you help.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanks to all,

I have achieved my requirement. I am closing this thread.

former_member183816
Active Participant
0 Kudos

DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

         

String FileName = conf.get(key);

String CRLF="\r\n";

String emailPackage=

                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+CRLF+

                    "<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"+CRLF+

                                "<Subject>Delivery notes</Subject>"+CRLF+

                    "<From>test@test.com</From>"+CRLF+

                    "<To>ambuj.mishra@      .com;someoneelse@   .com</To>"+CRLF+

         "<Reply_To />"+CRLF+

                    "<Content_Type>text/plain</Content_Type>"+CRLF+

                  "<Content_Disposition>attachment; filename="+"\""+FileName+"\""+"</Content_Disposition>"+CRLF+

  "<Content>"+"my file data"+"</Content>"+CRLF+

                            "</ns:Mail>";

return emailPackage;

trying to put ContentType in Header output.  

"Trying to put FileName in Header from Source to Content type in target" ??

For that, write a udf, concatenate udf output to "_DDMMYYYY" and map it to ContentType in target email package.


DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

         

String FileName = conf.get(key);

return FileName;

Former Member
0 Kudos

Thanks for reply. But in my case I am using Java mapping. please advice.

former_member184720
Active Contributor
0 Kudos

Did you check this blog? Also has code snippet for Java mapping

former_member183816
Active Participant
0 Kudos

public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException

{

try{

       

       // Getting output stream to write email package

            OutputStream os = out.getOutputPayload().getOutputStream(); 

  DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

        

  String FileName = conf.get(key);

  SimpleDateFormat dt = new SimpleDateFormat("YYYYMMDD");

        Date date = new Date();

  FileName=FileName+"_"+dt.format(date);

      // forming Email Package

             String emailPackage=

             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+CRLF+

              "<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"+CRLF+

              "<Subject>Delivery notes</Subject>"+CRLF+

               "<From>certificates@    .com</From>"+CRLF+

                "<To>ambuj.mishra@      .com;someoneelse@   .com</To>"+CRLF+

                "<Reply_To />"+CRLF+

                  "<Content_Type>text/plain</Content_Type>"+CRLF+

                    "<Content_Disposition>attachment; filename="+"\""+FileName+"\""+"</Content_Disposition>"+CRLF+

                       "<Content>"+"file content"+"</Content>"+CRLF+

                            "</ns:Mail>";                   

             // writing Email Package

                 os.write(emailPackage.getBytes());                

                 os.flush();

                 os.close();                                                                

         }

         catch (Exception e)

         {

             throw new StreamTransformationException(e.getMessage());

         }

    }                               

Former Member
0 Kudos

Hi Thanks Mishra.

But if I write mail package from output, then wt about payload?

former_member183816
Active Participant
0 Kudos

public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException

{

try{

       

       // Getting output stream to write email package

            OutputStream os = out.getOutputPayload().getOutputStream(); 

  DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

        

  String FileName = conf.get(key);

  SimpleDateFormat dt = new SimpleDateFormat("YYYYMMDD");

        Date date = new Date();

  FileName=FileName+"_"+dt.format(date);

  String attachmentContent="This is my attachment content";

      

  //creating output attachment

            OutputAttachments outAtt = out.getOutputAttachments();

  Attachment newAttachment = out.getOutputAttachments().create(FileName, attachmentContent.getBytes());  

            outAtt.setAttachment(newAttachment);

      // forming Email Package

             String emailPackage=

             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+CRLF+

              "<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"+CRLF+

              "<Subject>Delivery notes</Subject>"+CRLF+

               "<From>certificates@    .com</From>"+CRLF+

                "<To>ambuj.mishra@      .com;someoneelse@   .com</To>"+CRLF+

                "<Reply_To />"+CRLF+

                  "<Content_Type></Content_Type>"+CRLF+               

                       "<Content>"+"This is my payload, here it is writing it..."+"</Content>"+CRLF+

                            "</ns:Mail>";                   

             // writing Email Package

                 os.write(emailPackage.getBytes());                

                 os.flush();

                 os.close();                                                                

         }

         catch (Exception e)

         {

             throw new StreamTransformationException(e.getMessage());

         }

    }                               

your payload will be in <Content> and your file will be created as attachment with File name , coming in header.

Former Member
0 Kudos

Hi,

I am not able to get payload in attachment. I think before writing the code I need to attach the pay load. above code is not working for payload attachment. please help

former_member183816
Active Participant
0 Kudos

Don't copy paste above code, and expect you will get your result instantly. Modify it accordingly. Your requirement is not clear at all. what are you trying to acheive?

Read these,

https://help.sap.com/javadocs/pi/pi711/com/sap/engine/interfaces/messaging/api/Payload.html

http://help.sap.com/saphelp_nw73/helpdata/en/6b/4493404f673028e10000000a1550b0/content.htm

Former Member
0 Kudos

Thanks for replay

azharshaikh
Active Contributor
0 Kudos

Hi,

You can pick the filename from Sender SFTP using Dynamic Configuration and pass it to your header file.

DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

            String FileName = conf.get(key);

           conf.put(key, Filename);

Are you using Mail Package at Receiver end?

Regards,

Azhar

Former Member
0 Kudos

Hi Azhar,

Thanks for your reply. putting key in configuration is will not work for mail adapter. That is the issue here.