DataPower

DataPower

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

How to send email with attachment from DataPower?

  • 1.  How to send email with attachment from DataPower?

    Posted Fri November 06, 2020 06:28 PM

    Dear Sir/Madam,

    My DataPower service needs to send email with attachment from DataPower. I searched DataPower Forum for this, I see a list of similar question. But as the links in the anwsers no loger work, I still don't see the answer for how to send email with attachment from DataPower. Can you give me a working example xsl code that sends email with attachment using url-open call?

    Thanks a lot in advance

    Tang



    #DataPower
    #Support
    #SupportMigration


  • 2.  RE: How to send email with attachment from DataPower?

    Posted Fri November 27, 2020 08:15 AM

    Hello

    Have you see Hermann post ?

    <!--

    DataPower sends HTML body email with binary data attachment (animated .gif).

    see http://ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/smtp2

    -->

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" xmlns:mime="urn:iso:identified-organization:dod:internet:mail:mixer" xmlns:func="http://exslt.org/functions" extension-element-prefixes="dp" exclude-result-prefixes="func mime">

    <xsl:output omit-xml-declaration="yes" cdata-section-elements="body"/>

    <xsl:template match="/">

    <!-- HTML email text -->

    <xsl:variable name="html">

    mail <b>bold</b>

    <i>italic</i> text<br/>

    <br/>

    <a href="https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/sum_of_pascal_s_triangle_reciprocals10">Blog</a> entry on sum of Pascal's triangle reciprocals.

    <p/>

    <span style="font-size: 1.5em;">∑<sup>∞</sup>

    <sub>i=j+1</sub>&#160;<sup>1</sup>/<sub>(i choose j)</sub> = <sup>1</sup>/<sub>(j-1)</sub> , &#160;&#160;&#160;j≥2</span>

    <p/>

    </xsl:variable>

    <!-- get real binary data for attaching to email (animated .gif) -->

    <xsl:variable name="gif">

    <dp:url-open target="http://stamm-wilbrandt.de/chess/en/Pb7/anim.gif" response="binaryNode"/>

    </xsl:variable>

    <!-- now just send the email ... -->

    <xsl:value-of select="mime:sendBodyWithAttachment(

    'mailExchange',

    'hermann',

    'johndoe',

    'datapower.ibm.com',

    'email with attachment 8',

    $html,

    dp:binary-encode($gif/result/binary),

    'image/gif',

    'anim.gif'

    )"/>

    </xsl:template>

    <!-- some constants -->

    <xsl:variable name="CRLF" select="'&#13;&#10;'"/>

    <xsl:variable name="DDASH" select="'--'"/>

    <xsl:variable name="QUOT" select="'&quot;'"/>

    <!-- MIME base64 data maximal line length is 76 characters -->

    <func:function name="mime:split64">

    <xsl:param name="str"/>

    <func:result>

    <xsl:value-of select="concat(substring($str,1,76),$CRLF)"/>

    <xsl:if test="string-length($str) > 76">

    <xsl:value-of select="mime:split64(substring($str,77))"/>

    </xsl:if>

    </func:result>

    </func:function>

    <!-- send email with HTML body and an attachment -->

    <func:function name="mime:sendBodyWithAttachment">

    <xsl:param name="exchange"/>

    <xsl:param name="to"/>

    <xsl:param name="from"/>

    <xsl:param name="domain"/>

    <xsl:param name="subject"/>

    <xsl:param name="html"/>

    <xsl:param name="att"/>

    <xsl:param name="coty"/>

    <xsl:param name="fname"/>

    <!-- prepare HTML email body for sending -->

    <xsl:variable name="serializedHTMLData">

    <dp:serialize select="$html" omit-xml-decl="yes"/>

    </xsl:variable>

    <!-- as the name says, get us a unique MIME boundary -->

    <xsl:variable name="boundary" select="dp:generate-uuid()"/>

    <!-- trick to make this working in func:function -->

    <xsl:variable name="dummy">

    <dp:url-open response="ignore" target="{concat(

    'smtp://',

    dp:encode($exchange,'url'),

    '/?Recpt=',

    dp:encode($to,'url'),

    '&amp;Sender=',

    dp:encode($from,'url'),

    '&amp;Subject=',

    dp:encode($subject,'url'),

    '&amp;Domain=',

    dp:encode($domain,'url'),

    '&amp;MIME=true'

    )}">

    <xsl:value-of disable-output-escaping="yes" select="concat('MIME-Version: 1.0',$CRLF)"/>

    <xsl:value-of disable-output-escaping="yes" select="concat('Content-type: multipart/mixed; boundary=',$QUOT)"/>

    <xsl:value-of disable-output-escaping="yes" select="concat($boundary,$QUOT,$CRLF)"/>

    <xsl:value-of disable-output-escaping="yes" select="concat($CRLF,$CRLF,$DDASH,$boundary,$CRLF)"/>

    <xsl:value-of disable-output-escaping="yes" select="concat('Content-type: text/html',$CRLF,$CRLF)"/>

    <xsl:value-of disable-output-escaping="yes" select="$serializedHTMLData"/>

    <xsl:value-of disable-output-escaping="yes" select="concat($CRLF,$DDASH,$boundary,$CRLF)"/>

    <xsl:value-of disable-output-escaping="yes" select="concat('Content-type: ',$coty,$CRLF)"/>

    <xsl:value-of disable-output-escaping="yes" select="concat('Content-Transfer-Encoding: base64',$CRLF)"/>

    <xsl:value-of disable-output-escaping="yes" select="concat('Content-Disposition: attachment;')"/>

    <xsl:value-of disable-output-escaping="yes" select="concat(' filename=',$fname,';',$CRLF,$CRLF)"/>

    <xsl:value-of disable-output-escaping="yes" select="mime:split64($att)"/>

    <xsl:value-of disable-output-escaping="yes" select="concat($DDASH,$boundary,$DDASH,$CRLF)"/>

    <xsl:value-of disable-output-escaping="yes" select="concat('epilogue',$CRLF)"/>

    </dp:url-open>

    </xsl:variable>

    <func:result select="'sent'"/>

    </func:function>

    </xsl:stylesheet>



    #DataPower
    #Support
    #SupportMigration


  • 3.  RE: How to send email with attachment from DataPower?

    Posted Tue September 21, 2021 04:13 PM

    Thanks a lot for your xsl code.



    #DataPower
    #Support
    #SupportMigration