IBM Support

Sending HTML data using IBM WebSphere DataPower SOA Appliance SMTP url-open extension function

Technote (troubleshooting)


You have tried using the DataPower Appliance SMTP url-open extension function to send HTML data but the recipient always gets the text version (HTML source code) of the data instead of the HTML formatted version.


Without the MIME parameter specified in the SMTP URL and the HTML Content-Type defined as part of the HTML data, the HTML data, when sent, will show in an email viewer in the HTML source code.

Resolving the problem

Below are the key steps and components needed in order to ensure the email viewer of the recipient displays the data in the HTML formatted version.

Service Configuration:
When configuring the service, ensure the following:
1. The request type of service should be XML. If 'Non-XML' request type is used, this could cause an empty email to be sent.
2. Enable 'Non-XML Processing' on the processing rule that executes to send the email. Steps required:
a. Click OBJECTS -> Processing Rule
b. Select the appropriate processing rule.
c. Select on for the 'Non-XML Processing' option. Normally, processing is only performed on XML content. This option allows processing actions to be performed on Non-XML content as well.

Stylesheet Definition:
1. When constructing the SMTP URL, add the MIME (Multipurpose Internet Mail Extensions) parameter to it and set it "true". That is:


2. Pass the HTML data as a base-64 encoded string to the dp:url-open extension function. If this does not work, use the dp:serialize extension function to serialize the HTML data, then use the dp:encode function to base-64 encode the serialized HTML data.

The first part of the data to be sent must specify the content-type as text/html followed by two combinations of carriage return (CR) and line feed (LF), then the HTML message. That is:

Content-Type: text/html\r\n\r\n (use 
 instead of '\r' and 
 in place of '\n')
<html><b>Test</b><html> ( this should be base-64 encoded)

3. The data-type attribute for the url-open must be set to "base64". This indicates that the input data is base64-encoded, in which case the data will be decoded prior to processing. The SMTP url-open definition may look like this:

    <dp:url-open target="{$smtpURL}" ..... data-type="base64">

Below is an educational sample provided for demonstration purposes only. This information has not been thoroughly tested under all conditions. It demonstrates one means of sending HTML email using SMTP url-open:

    <xsl:template match="/">
        <!-- Create the full smtp url that includes MIME=true  -->
        <xsl:variable name="smtpURL" select="'smtp://..../?Recpt=...&amp;Sender=....&amp;Subject=...&amp;Domain=...&amp;MIME=true'"/>

        <!-- get the HTML data to be sent -->
        <xsl:variable name="unSerializedHTMLData">
            <xsl:copy-of select="."/>

            Call the dp:serialize function to serialize the HTML data to be sent, thus generating an escaped version of the data. Also, set the 'omit-xml-decl' attribute of the dp:serialize function to "yes". This will cause the XML declaration not to be included in the output produced.
        <xsl:variable name="serializedHTMLData">
            <dp:serialize select="$unSerializedHTMLData"

            Construct the complete email data to send as follows:
            content-type: text/html\r\n\r\n <html><b>Test</b></html>
        <xsl:variable name="htmlData">content-type: text/html&#x0D;&#x0A;&#x0D;&#x0A;
            <xsl:copy-of select="$serializedHTMLData"/>

        <!-- base-64 encode the HTML data to be sent -->
        <xsl:variable name="encodedHTMLData"

            Set the target SMTP url, specify the data-type as "base64", and send the base-64 encoded HTML data. The recipient of this mail will receive "Test" in bold.
        <dp:url-open target="{$smtpURL}" response="ignore"
            <!-- get a copy of the base-64 encoded data -->
            <xsl:copy-of select="$encodedHTMLData"/>

For more information about the SMTP dp:url-open, dp:serialize, and dp:encode extension functions, refer to the IBM WebSphere DataPower SOA Appliances: Extension Elements and Functions Catalog.

To access documentation specific to each firmware version, see WebSphere DataPower Product Documentation.

Document information

More support for: IBM DataPower Gateways

Software version: 4.0.2, 5.0.0, 6.0.0, 6.0.1

Operating system(s): Firmware

Software edition: Edition Independent

Reference #: 1291029

Modified date: 03 June 2010

Translate this page: