DataPower

 View Only
  • 1.  dpsmtp:// - Adding cc and multiple mail ids in To: and CC: using XSLT

    Posted 21 days ago
    Edited by Stefen Salvatore 21 days ago

    Hi @Steve Linn and all,

    I have a requirement to initiate mail To: (multiple mail IDs) and adding cc: (multiple users) as well. However my code is working fine while I am sending to 1 user. Any help from anyone will be highly appreciated to fulfil my requirement. The following is sample xslt snippet.

    <xsl:value-of select="mime:sendBodyWithAttachment(
    'smtp.gmail.com',
    'xxx@x.com',
    'yyy.x@x.com',
    '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(
    'dpsmtp://',
    dp:encode($exchange,'url'),
    ':587/?To=',
    dp:encode($to,'url'),
    '&amp;From=',
    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>

    Also, Is there any possibility to implement the same using gatewayscript?


    Thankyou in Advance!



    ------------------------------
    Stefen Salvatore
    ------------------------------



  • 2.  RE: dpsmtp:// - Adding cc and multiple mail ids in To: and CC: using XSLT

    Posted 10 days ago

    Hi @Steve Linn and all

    Any inputs?

    Thankyou in advance.



    ------------------------------
    Stefen Salvatore
    ------------------------------



  • 3.  RE: dpsmtp:// - Adding cc and multiple mail ids in To: and CC: using XSLT

    Posted 7 days ago

    Hi Stefen,
    Let's answer the easier question first :-) GatewayScript only supports the http, https, mq, dpmq, and graphql protocols.  smtp protocols are not support in GatewayScript for urlopen, only supported with the dp:url-open extension element.

    As for how to resolve in xslt your multiple recipient question, I'll say up front I've never had to use the dp:url-open extension for the smtp protocol before, so I'm only going off of the documentation at https://www.ibm.com/docs/en/datapower-gateway/10.5.0?topic=open-url-smtp which I'm sure you're read and unfortunately there is not an example that shows multiple recipients.  How have you specified your "To" argument to your function and what failures are you seeing in the DataPower log?  If I had to guess, perhaps the multiple addresses must be semicolon ; or semicolon and space separated?

    Best Regards,
    Steve Linn



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------