I don't believe I ever tried this, but it should be doable.
When sending SMTP, the server doesn't differentiate between recipient "types." That's a "mail client" thing based on metadata at the beginning of the content of the message body (DATA). So... to accomplish what you're looking for:
Try specifying the "&To=" query parameter multiple times in the URL passed to dp:url-open(). Once for each recipient, regardless of whether they're a "To:" or a "Cc:" recipient. SMPT only understands "RCPT TO:" commands. There is no "RCPT CC:" SMTP command. When sending the message, the value after the '=' of "&To=" is used to construct the "RCPT TO:" SMTP command. "RCPT TO:" can only have a single recipient per line, but you can have multiple "RCPT TO:" lines in a single SMTP transaction.
Original Message:
Sent: Thu June 27, 2024 04:30 PM
From: Steve Linn
Subject: dpsmtp:// - Adding cc and multiple mail ids in To: and CC: using XSLT
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
Original Message:
Sent: Fri June 14, 2024 02:22 AM
From: Stefen Salvatore
Subject: dpsmtp:// - Adding cc and multiple mail ids in To: and CC: using XSLT
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="' '"/>
<xsl:variable name="DDASH" select="'--'"/>
<xsl:variable name="QUOT" select="'"'"/>
<!-- 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'),
'&From=',
dp:encode($from,'url'),
'&Subject=',
dp:encode($subject,'url'),
'&Domain=',
dp:encode($domain,'url'),
'&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
------------------------------