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

Technote (troubleshooting)


Problem(Abstract)

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.

Cause

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:

smtp://msgRecipient@mailExchangerName/?Sender=....&Subject=...&Domain=...&MIME=true

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">
      ----
    </dp:url-open>


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="."/>
        </xsl:variable>

        <!--
            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"
                omit-xml-decl="yes"/>
        </xsl:variable>

        <!--
            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"/>
        </xsl:variable>

        <!-- base-64 encode the HTML data to be sent -->
        <xsl:variable name="encodedHTMLData"
            select="dp:encode($htmlData,'base-64')"/>

        <!--
            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"
                data-type="base64">
            <!-- get a copy of the base-64 encoded data -->
            <xsl:copy-of select="$encodedHTMLData"/>
        </dp:url-open>
    </xsl:template>


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.

Rate this page:

(0 users)Average rating

Document information


More support for:

WebSphere DataPower SOA Appliances
General

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:

2010-06-03

Translate my page

Machine Translation

Content navigation