Skip to Content

Email receiver creates MainDocument.xml instead of mail body

Hello,

im using a JAVA-Mapping with mail package to create a mail with content and attachment.

This is my Coding.

InputStream inputstream = input.getInputPayload().getInputStream();
OutputStream outputstream = output.getOutputPayload().getOutputStream();

String mailOutput = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
        + "<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">\n"
        + " <Subject>" + subject + "</Subject>\n"
        + " <From>" + mailFromAdress + "</From>\n"
        + " <To>" + mailToAdress + "</To>\n"
        + " <Reply_To/>\n"
        + " <Content_Type>text/plain</Content_Type>\n"
        + " <Content>MailContent</Content>\n"
        + "</ns:Mail>";
outputstream.write(mailOutput.getBytes());

byte[] bAttachment = new byte[inputstream.available()];
inputstream.read(bAttachment);
Attachment newAttachment = output.getOutputAttachments().create(attachmentname, "application/xml", bAttachment);
output.getOutputAttachments().setAttachment(newAttachment);

this is the configuration of the mail receiver.

the output is always the same.

two XML-Documents

The first with the text "MailContent".

The second with the right output as attachment.

what do i have to do to convert the MainDocument a real text in the mail body?

My result should be one mail with one attachment and a text as body. Either plain or als html.

br

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Oct 28, 2015 at 02:28 AM

    Hi Christian

    First of all, the use of Mail Package is deprecated.

    Refer to Stefan's blog below on how to create an email with attachments without Mail Package.

    Create email with body and attachments for binary payload with Java mapping

    However, if you insist on using Mail Package, you need to set the ContentDisposition to "inline" so that the Main Document is set as the mail body. You can use MessageTransformBean to set it - refer section 3.2.4 in the following document

    How to Use the Mail Adapter of the Exchange Infrastructure 3.0 J2EE Adapter Engine (NW2004)

    Here's another alternative using Mail Package where you manually construct the whole MIME stream for the body and attachments.

    Rgds

    Eng Swee

    Add comment
    10|10000 characters needed characters exceeded