Recently I worked on a scenario where the requirement was to send email with HTML content in body and source file as an attachment.

HTML content can also be generated with XSLT mapping along with Message/Java Mapping. But why to use multimapping, when we can get the result in one mapping.

For this scenario, I used only Java mapping to generate the Mail Package structure with the HTML content, styled with CSS.

CSS helps to describes how HTML elements are to be displayed.

Here, I have used internal CSS to format the mail body as it is easier to demonstrate the style.

Lets refer to the below Java code.

Java Mapping to create Mail Package Structure :

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



String inputdata = in.getInputPayload().getInputStream();

mailSubject = “Sample Email with attachment”;
attachmentName = File_Name;                           //filename can be populated dynamically from message header

mailContent = “

” + CRLF
+”” + CRLF
+”” + CRLF

” + CRLF
+”” + CRLF

” + CRLF



” + CRLF

+”DATE: ” +Date+ CRLF                                               //Can be populated dynamically
Message ID: ” +msgID+ CRLF


Please see the attachment for original File.” + CRLF


” + CRLF
+”” + CRLF
+”” + CRLF;

//create XML structure of mail package

String output = “”
+ “”
+ “” + Mail Subject + “”
+ “” + sender email ID + “”
+ “” + Receiver email ID + “”
+ “multipart/mixed; boundary=”” + boundary + “””
+ “”;


// create the declaration of the MIME parts

//First part. It will contain the HTML content

output = “–” + boundary + CRLF
+ “Content-Type: text/html; charset=UTF-8” + CRLF
+ “Content-Disposition: inline” + CRLF + CRLF
+ mailContent + CRLF

//Second part. It contains data to be sent as an attachment.

+ “–” + boundary + CRLF
+ “Content-Type: application/xml; name=” + attachmentName + CRLF
+ “Content-Disposition: attachment; filename=” + attachmentName + CRLF + CRLF;

copySource(inputdata, out.getOutputPayload().getOutputStream());


catch (Exception e){}


protected static void copySource(InputStream in, OutputStream out) throws IOException, StreamTransformationException

int c;

while ((c = != -1){
out.write(c); }


catch(Exception e){}


On implementing the Java mapping, the below mail package structure is generated as XML message. The output contains multiple parts where the first part is HTML text with CSS style and the second part is data from source payload which is sent as an attachment.

Also, please remember to select Use Mail Package, Content Encoding as ‘None’ and Keep Attachments as checked in the receiver communication channel.

Mail Package Structure :

Sample Email with attachment
[email protected]
multipart/mixed; boundary=”–AaZz”
Content-Type: text/html; charset=UTF-8
Content-Disposition: inline




DATE: 20171129T231100Z

Message ID: f82b3c5c-cb1a-11e7-8fbe-0000182374d2

Please see the attachment for original File.

Content-Type: application/xml; name=Test_File.edi
Content-Disposition: attachment; filename=Test_File.ediUNA:+.? ‘UNB+UNOC:3+1111111111111:14+5790000075003:14+150601:1528+V434687+++++EANCOM’UNH+77+INVOIC:D:01B:UN:EAN010′
DTM+ZPE:20150601:102’FTX+ZZZ+1+ST2+Rahmen- und Kond:itionsvereinbarungen.+DE’
MOA+8:100.57’MOA+25:8522.85’LIN+1++3073781054132:SRV’PIA+1+00433482:SA::91’IMD+A++:::LRD MIX3 225/260G X 20 STD’

HTML Email :

Email 2489026

NOTE: This approach only works with non binary attachments.

New NetWeaver Information at

Very Helpfull



User Rating: Be the first one !