cancel
Showing results for 
Search instead for 
Did you mean: 

How send e-mail with XML + PDF and body text

rhviana
Active Contributor
0 Kudos

Hi everyone,

I have a new requirement but I´m with doubts, how to send an e-mail with two attachements (XML and PDF) and body text using -

MIME: multipart/mixed;boundary

I already have code to send XML + body text as you can see below:


Element contentType = docout.createElement("Content_Type");

  root.appendChild(contentType);

  Text contentTypeText = docout.createTextNode("multipart/mixed;boundary=--AaZz");

  absTraceLog.addDebugMessage("Content_Type e-mail --- "+contentTypeText.toString());

  contentType.appendChild(contentTypeText)

String text = "----AaZz\r\nContent-Type: text/plain; charset=UTF-8\r\n" +

        "Content-Disposition: inline\r\n\r\n" + nfeText +

        "\r\n----AaZz\r\nContent-Disposition: attachment; filename="+ prefixo +" "+ chaveNFe +".xml" +"\r\n\r\n" + xmlString + "\r\n";

Element content = docout.createElement("Content");

root.appendChild(content);

contentText = docout.createTextNode(text);

Content.appendChild(contentText);

The code above work good, but I can´t duplicate any field from XiMail 3.0 - because it´s 0:1.

So how to do that ?

Thanks.

Regards,

BR.

Viana.

Accepted Solutions (1)

Accepted Solutions (1)

engswee
Active Contributor
0 Kudos

Hi Ricardo

Just my two cents.

If you have multiple attachments, have you considered NOT using the Mail Package, and selecting "Keep Attachments" in the receiver channel?

You create the two attachments during the mapping part, and forward them at the adapter.

Rgds

Eng Swee

rhviana
Active Contributor
0 Kudos

Eng,

Thanks for coins, it´s helps.

What you mean mapping part ? Use a MM ? Module Adapter ?

If I can´t use a Mail Package, how to build the body text ?


See ya,

BR.

Ricardo Viana.

engswee
Active Contributor
0 Kudos

Hi Ricardo

The reason for my suggestion is because usage of Mail Package is deprecated - refer note 856599.

The body text can be taken from the MainDocument. You can refer to the below document, item 3.2.4 where it describes sending a mail with body and attachments. The MainDocument payload can be set as the body by setting the ContentDisposition to inline.

What you mean mapping part ? Use a MM ? Module Adapter ?

I meant Operation Mapping (using either a Java Mapping or Message Mapping with UDF) to set the attachments.

Rgds

Eng Swee

rhviana
Active Contributor
0 Kudos

Eng,

I find way to do that via MailPackage.

I will test and provide solution.

Regards until now.

BR.

Ricardo Viana.

rhviana
Active Contributor
0 Kudos

Eng,

That´s works good with mailPackage:

            content= "--" + "--Zz" + CRLF

                    + "Content-Type: text/html; charset=UTF-8" + CRLF

                    + "Content-Disposition: inline" + CRLF + CRLF

                    + textBodyMail + CRLF

                    + "--" + "--Zz" + CRLF

                    + "Content-Type: application/xml; name=" + attachmentName + CRLF

                    + "Content-Disposition: attachment; filename=" + attachmentName + CRLF

                    + "Content-Transfer-Encoding: base64" + CRLF + CRLF

                    + encoder.encode(inputString.getBytes("UTF-8")) + CRLF

                    + "--" + "--Zz" + CRLF

                    + "Content-Type: application/pdf; name=" + pdfName + CRLF

                    + "Content-Disposition: attachment; filename=" + pdfName + CRLF

                    + "Content-Transfer-Encoding: base64" + CRLF + CRLF

                    + encoder.encodeBuffer(new BASE64Decoder().decodeBuffer(pdfAttachment));

Regards,

BR.

Ricardo Viana.

engswee
Active Contributor
0 Kudos

Hi Ricardo

Good to hear that. Thanks for sharing the solution. So in essence, you just have to add a subsequent portion separated by the boundary --Zz, right?

Rgds

Eng Swee

rhviana
Active Contributor
0 Kudos

Eng,

No worries man !!

The boundary will be --Zz or anything you want --Text Attachment / -- Xx / --007Bond - for exemple, and you must concat the content-disposition fields and not create a new one because cardinality definded into XSD 0:1.

Regards,

BR.

Ricardo Viana

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Everyone,

I am trying to send email with body and XML attachment ( with .txt extension ).

I am using same way of preparing message as Ricardo's working solution mentioned above without using encoder part.

Email is going OK with body and attachment. But attachment data is getting line breaks after 2050 characters.

I want to try using  "encoder.encode(inputString.getBytes("UTF-8")) "

Does anyone give me what class we should use to create that encoder object to send xml data with .txt extension ?

Any help is appreciated.

Former Member
0 Kudos

Hi Everyone,

     With above mentioned issue, I am using Mail Message Protocol XIPAYLOAD with "Use Mail Package" checked and Content Encoding "None" and "Keep Attachments" unchecked.

I tried BASE64Encoder but it does not work. Can you please suggest what Encoder might work.

Thank you

Former Member
0 Kudos

I used com.sap.aii.utilxi.base64.api.Base64 class and it is working. thanks.