Topic
  • 41 replies
  • Latest Post - ‏2014-01-03T12:47:46Z by Daviiid
SystemAdmin
SystemAdmin
6772 Posts

Pinned topic Sending emails with DataPower appliance (X150 v4.1.0.4)

‏2011-11-23T23:31:31Z |
Hi,

I have a requirement to send emails using DataPower appliance. After doing some research online, I found that I can use dp:url-open() function for this purpose but I wanted to know if someone has successfully implemented anything like this?

Also, is it possible to send email to multiple recipients using dp:url-open() function for SMTP?

I also have a requirement to add an attachment to the email along with the normal email-body, is that do-able?

If someone can point me to some documentation or provide some guidance for this that would be great....thanks...
Updated on 2013-01-07T08:56:14Z at 2013-01-07T08:56:14Z by Daviiid
  • HermannSW
    HermannSW
    4903 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2011-11-24T08:30:48Z  
    This spring we had a thread on smtp and attachments.

    Using forum search with "smtp attachment" this is the thread:
    https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14679164&#14679164

    Hermann.
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2011-12-13T23:08:46Z  
    • HermannSW
    • ‏2011-11-24T08:30:48Z
    This spring we had a thread on smtp and attachments.

    Using forum search with "smtp attachment" this is the thread:
    https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14679164&#14679164

    Hermann.
    Thanks for your response Hermann. But, I am still not clear about the following:

    1. Is it possible to send email to multiple recipients using dp:url-open() for smtp, also it is possible to have CC and BCC email recipients?
    2. Also, I am still not able to understand how to send an email with normal body and an attachment using dp:url-open() for smtp. I am able to send not plain text emails.

    Any help or examples in this regard would be highly appreciated.
  • dp_developer
    dp_developer
    31 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2011-12-14T14:18:17Z  
    • HermannSW
    • ‏2011-11-24T08:30:48Z
    This spring we had a thread on smtp and attachments.

    Using forum search with "smtp attachment" this is the thread:
    https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14679164&#14679164

    Hermann.
    Hi Hermann ,

    Can you please try and post a working XSL to send an e-mail with attachments (say an excel sheet or a pdf etc). It would be of great help .
    Thanks in advance .
  • HermannSW
    HermannSW
    4903 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2011-12-15T21:15:26Z  
    Hi Hermann ,

    Can you please try and post a working XSL to send an e-mail with attachments (say an excel sheet or a pdf etc). It would be of great help .
    Thanks in advance .
    Hi Rahul,

    > Hi Hermann ,
    >
    > Can you please try and post a working XSL to send an e-mail with attachments (say an excel sheet or a pdf etc). It would be of great help .
    >
    >
    > Thanks in advance .
    >
    find the stylesheet smtp.xsl attached here.

    Find everything else (comments, screenshots, ...) in this smtp blog posting.

     
    Hermann<myXsltBlog/>

    Attachments

  • HermannSW
    HermannSW
    4903 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2011-12-15T22:24:19Z  
    • HermannSW
    • ‏2011-12-15T21:15:26Z
    Hi Rahul,

    > Hi Hermann ,
    >
    > Can you please try and post a working XSL to send an e-mail with attachments (say an excel sheet or a pdf etc). It would be of great help .
    >
    >
    > Thanks in advance .
    >
    find the stylesheet smtp.xsl attached here.

    Find everything else (comments, screenshots, ...) in this smtp blog posting.

     
    Hermann<myXsltBlog/>
    Ups, this is a better link ...
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/smtp2
  • dp_developer
    dp_developer
    31 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2011-12-16T11:57:18Z  
    • HermannSW
    • ‏2011-12-15T22:24:19Z
    Thanks a ton Hermann...I put the values of my mail server and other details and it worked like a charm . Will get back incase of any other queries .
  • HermannSW
    HermannSW
    4903 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2011-12-20T07:56:43Z  
    • HermannSW
    • ‏2011-12-15T22:24:19Z
    Just for completeness, code listing of smtp.xslhttp://www.ibm.com/developerworks/forums/servlet/JiveServlet/download/1198-402725-14769696-376200/smtp.xsl below in addition to the screenshots from the blog posting:
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/smtp2

    Using coproc2 to execute smtp.xsl returns "sent".


    The email got sent to my private email address.
    This screenshot of my webmail client proves that sending the email with attachment really worked:


    smtp.xsl:
    
    <!-- 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" />     <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></p><span style=
    "font-size: 1.5em;">∑<sup>∞</sup><sub>i=j+1</sub> <sup>1</sup>/<sub>(i choose j)</sub> = <sup>1</sup>/<sub>(j-1)</sub> ,    j≥2</span><p></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@stamm-wilbrandt.de', 
    'johndoe@ibm.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( 
    '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>
    


     
    Hermann<myXsltBlog/>
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2011-12-22T19:50:55Z  
    • HermannSW
    • ‏2011-12-20T07:56:43Z
    Just for completeness, code listing of smtp.xslhttp://www.ibm.com/developerworks/forums/servlet/JiveServlet/download/1198-402725-14769696-376200/smtp.xsl below in addition to the screenshots from the blog posting:
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/smtp2

    Using coproc2 to execute smtp.xsl returns "sent".


    The email got sent to my private email address.
    This screenshot of my webmail client proves that sending the email with attachment really worked:


    smtp.xsl:
    <pre class="jive-pre"> <!-- 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" /> <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></p><span style= "font-size: 1.5em;">∑<sup>∞</sup><sub>i=j+1</sub> <sup>1</sup>/<sub>(i choose j)</sub> = <sup>1</sup>/<sub>(j-1)</sub> , j≥2</span><p></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@stamm-wilbrandt.de', 'johndoe@ibm.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( '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> </pre>

     
    Hermann<myXsltBlog/>
    Thank you so much Hermann...it worked like a charm.

    I still have one query: can we send emails to multiple recepients, without using distribution list and also is it possible to add CC and BCC email address in the email that goes out.
    Once agian I really appreciate all the help you provided, it really made my work just a piece of cake.
  • HermannSW
    HermannSW
    4903 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2011-12-22T21:06:17Z  
    Thank you so much Hermann...it worked like a charm.

    I still have one query: can we send emails to multiple recepients, without using distribution list and also is it possible to add CC and BCC email address in the email that goes out.
    Once agian I really appreciate all the help you provided, it really made my work just a piece of cake.
    > ..
    > I still have one query: can we send emails to multiple recepients, without using distribution list and also is it possible to add CC and BCC email address in the email that goes out.
    >
    Sorry, that is not possible -- you can only specify one recipient:
    http://publib.boulder.ibm.com/infocenter/wsdatap/4mt/index.jsp?topic=%2Fcom.ibm.dp.xb.doc%2Fextensionfunctions43.htm&resultof=%22url-open%22%20%22smtp%22

    I think this is because a dp:url-open is a single network connection -- multiple recipients or cc would require multiple connections ...

     
    Hermann<myXsltBlog/>
  • triniman10
    triniman10
    29 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-02-21T20:35:16Z  
    • HermannSW
    • ‏2011-12-20T07:56:43Z
    Just for completeness, code listing of smtp.xslhttp://www.ibm.com/developerworks/forums/servlet/JiveServlet/download/1198-402725-14769696-376200/smtp.xsl below in addition to the screenshots from the blog posting:
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/smtp2

    Using coproc2 to execute smtp.xsl returns "sent".


    The email got sent to my private email address.
    This screenshot of my webmail client proves that sending the email with attachment really worked:


    smtp.xsl:
    <pre class="jive-pre"> <!-- 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" /> <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></p><span style= "font-size: 1.5em;">∑<sup>∞</sup><sub>i=j+1</sub> <sup>1</sup>/<sub>(i choose j)</sub> = <sup>1</sup>/<sub>(j-1)</sub> , j≥2</span><p></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@stamm-wilbrandt.de', 'johndoe@ibm.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( '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> </pre>

     
    Hermann<myXsltBlog/>
    Hi Hermann. I am new to using stylesheets and we have a requirement for a client is sending an MTOM attachment via a web service call to the DP endpoint. For an initial test would like to email the attachment to the client to prove out this capability in DataPower. I've used your stmp.xsl to prove that DP can email at attachment however I'm having trouble extending this stylesheet to include the MTOM attachment. Since the MTOM is binary as well, I thought it would be easy enough to reference the attachment value from the attachment manifest but it seems that it's require more parsing/manipulation in the stylesheet that what I'm used too. Can you provide some insight in how to work with the attachment manifest to send the attachment in an email.
  • HermannSW
    HermannSW
    4903 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-02-23T14:29:46Z  
    Hi Hermann. I am new to using stylesheets and we have a requirement for a client is sending an MTOM attachment via a web service call to the DP endpoint. For an initial test would like to email the attachment to the client to prove out this capability in DataPower. I've used your stmp.xsl to prove that DP can email at attachment however I'm having trouble extending this stylesheet to include the MTOM attachment. Since the MTOM is binary as well, I thought it would be easy enough to reference the attachment value from the attachment manifest but it seems that it's require more parsing/manipulation in the stylesheet that what I'm used too. Can you provide some insight in how to work with the attachment manifest to send the attachment in an email.
    Hi,

    > ... For an initial test would like to email the attachment to the client to prove out this capability in DataPower.
    > I've used your stmp.xsl to prove that DP can email at attachment
    >
    good.

    >however I'm having trouble extending this stylesheet to include the MTOM attachment. Since the MTOM is binary as well,
    > I thought it would be easy enough to reference the attachment value from the attachment manifest
    >
    correct.

    > but it seems that it's require more parsing/manipulation in the stylesheet that what I'm used too.
    > Can you provide some insight in how to work with the attachment manifest to send the attachment in an email.

    Posting on "pgm1st.xsl" seems to be what you are searching for -- it
    • determines the 1st (binary) pgm file from attachment-manifest
    • extracts it (of course response="binaryNode')
    • and sends to output -- you would need to send as part of the email ...
    https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14672215#14672215

     
    Hermann<myXsltBlog/>
  • triniman10
    triniman10
    29 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-02-24T17:02:32Z  
    • HermannSW
    • ‏2012-02-23T14:29:46Z
    Hi,

    > ... For an initial test would like to email the attachment to the client to prove out this capability in DataPower.
    > I've used your stmp.xsl to prove that DP can email at attachment
    >
    good.

    >however I'm having trouble extending this stylesheet to include the MTOM attachment. Since the MTOM is binary as well,
    > I thought it would be easy enough to reference the attachment value from the attachment manifest
    >
    correct.

    > but it seems that it's require more parsing/manipulation in the stylesheet that what I'm used too.
    > Can you provide some insight in how to work with the attachment manifest to send the attachment in an email.

    Posting on "pgm1st.xsl" seems to be what you are searching for -- it
    • determines the 1st (binary) pgm file from attachment-manifest
    • extracts it (of course response="binaryNode')
    • and sends to output -- you would need to send as part of the email ...
    https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14672215#14672215

     
    Hermann<myXsltBlog/>
    Thanks and that has allowed me to parse the incoming message for the attachment and send it via email. The issue now is that the email content shows as **** BINARY NODE **** and the attachment is not readable. I somewhat combined your smtp.xsl and pgm1st.xsl to produce this result and here's what that looked like:
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY ATTMAN "dp:variable('var://local/attachment-manifest')">
    <!ENTITY ATTHDR "/manifest/attachments/attachment/header">
    ]>
    <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">
    <dp:input-mapping href="store:///pkcs7-convert-input.ffd" type="ffd"/>
    <xsl:output method="text"/>
    <xsl:template match="/">
    <!-- HTML email text -->
    <xsl:variable name="html">
    <xsl:copy-of select="."/>
    </xsl:variable>
    <xsl:variable name="atthdrs" select="&ATTMAN;&ATTHDR;"/>
    <xsl:message dp:priority="debug">atthdrs: <xsl:value-of select="$atthdrs"/></xsl:message>
    <xsl:variable name="pgm1st" select="$atthdrs
    [1]"/>
    <xsl:message dp:priority="debug">pgm1st: <xsl:value-of select="$pgm1st"/></xsl:message>
    <xsl:variable name="resp">
    <dp:url-open target="{$pgm1st/../uri}" response="binaryNode"/>
    </xsl:variable>
    <xsl:message dp:priority="debug">resp: <xsl:value-of select="$resp"/></xsl:message>
    <dp:strip-attachments/>
    <xsl:variable name="attchmnt">
    <object>
    <message>
    <xsl:copy-of select="$resp/result/binary/node()"/>
    </message>
    </object>
    </xsl:variable>
    <!-- now just send the email ... -->
    <xsl:value-of select="mime:sendBodyWithAttachment(
    'mailServer',
    'Recipient',
    'Sender',
    'Domain',
    'Subject',
    $html,
    dp:binary-encode($attchmnt),
    'image/jpeg',
    'test.jpeg'
    )"/>
    </xsl:template>
    .
    .
    .
    .

    Of course, none of my xsl:message statements display anything which tells me I'm not converting them to text?
    Also, I know I'm butchering extending your style sheets but can you shed light on a couple of actions I'm attempting to take here:
    1) how to read in the attachment from the binarynode to send via smtp
    2) it seems the pgm1st.xsl is coded for a specific Content-Type (image/x-portable-greymap) and the messages I need to handle can be of any legitimate type(txt/pdf/jpg etc). How would I go about handling that variable for all types?

    I appreciate your assistance and your patience with what I'm sure are trivial questions to more experienced developers:)
  • HermannSW
    HermannSW
    4903 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-02-28T14:38:54Z  
    Thanks and that has allowed me to parse the incoming message for the attachment and send it via email. The issue now is that the email content shows as **** BINARY NODE **** and the attachment is not readable. I somewhat combined your smtp.xsl and pgm1st.xsl to produce this result and here's what that looked like:
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY ATTMAN "dp:variable('var://local/attachment-manifest')">
    <!ENTITY ATTHDR "/manifest/attachments/attachment/header">
    ]>
    <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">
    <dp:input-mapping href="store:///pkcs7-convert-input.ffd" type="ffd"/>
    <xsl:output method="text"/>
    <xsl:template match="/">
    <!-- HTML email text -->
    <xsl:variable name="html">
    <xsl:copy-of select="."/>
    </xsl:variable>
    <xsl:variable name="atthdrs" select="&ATTMAN;&ATTHDR;"/>
    <xsl:message dp:priority="debug">atthdrs: <xsl:value-of select="$atthdrs"/></xsl:message>
    <xsl:variable name="pgm1st" select="$atthdrs
    [1]"/>
    <xsl:message dp:priority="debug">pgm1st: <xsl:value-of select="$pgm1st"/></xsl:message>
    <xsl:variable name="resp">
    <dp:url-open target="{$pgm1st/../uri}" response="binaryNode"/>
    </xsl:variable>
    <xsl:message dp:priority="debug">resp: <xsl:value-of select="$resp"/></xsl:message>
    <dp:strip-attachments/>
    <xsl:variable name="attchmnt">
    <object>
    <message>
    <xsl:copy-of select="$resp/result/binary/node()"/>
    </message>
    </object>
    </xsl:variable>
    <!-- now just send the email ... -->
    <xsl:value-of select="mime:sendBodyWithAttachment(
    'mailServer',
    'Recipient',
    'Sender',
    'Domain',
    'Subject',
    $html,
    dp:binary-encode($attchmnt),
    'image/jpeg',
    'test.jpeg'
    )"/>
    </xsl:template>
    .
    .
    .
    .

    Of course, none of my xsl:message statements display anything which tells me I'm not converting them to text?
    Also, I know I'm butchering extending your style sheets but can you shed light on a couple of actions I'm attempting to take here:
    1) how to read in the attachment from the binarynode to send via smtp
    2) it seems the pgm1st.xsl is coded for a specific Content-Type (image/x-portable-greymap) and the messages I need to handle can be of any legitimate type(txt/pdf/jpg etc). How would I go about handling that variable for all types?

    I appreciate your assistance and your patience with what I'm sure are trivial questions to more experienced developers:)
    > ...
    > Of course, none of my xsl:message statements display anything which tells me I'm not converting them to text?
    If you can see "***BINARY NODE***" then you can use "dp:binary-encode(...)" to log the value base64 encoded to the log.
    That does work for any, also binary, data.

    > Also, I know I'm butchering extending your style sheets but can you shed light on a couple of actions I'm attempting to take here:
    > 1) how to read in the attachment from the binarynode to send via smtp
    See getgif.xsl sample on slide 18 from this WSTE webcast:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

    > 2) it seems the pgm1st.xsl is coded for a specific Content-Type (image/x-portable-greymap) and the messages I need to handle can be of any legitimate type(txt/pdf/jpg etc). How would I go about handling that variable for all types?
    >
    You can select by name alternatively, just query "dp:variable('var://local/attachment-manifest')", does not need to be by content type.

     
    Hermann<myXsltBlog/>
  • triniman10
    triniman10
    29 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-02-29T18:04:04Z  
    • HermannSW
    • ‏2012-02-28T14:38:54Z
    > ...
    > Of course, none of my xsl:message statements display anything which tells me I'm not converting them to text?
    If you can see "***BINARY NODE***" then you can use "dp:binary-encode(...)" to log the value base64 encoded to the log.
    That does work for any, also binary, data.

    > Also, I know I'm butchering extending your style sheets but can you shed light on a couple of actions I'm attempting to take here:
    > 1) how to read in the attachment from the binarynode to send via smtp
    See getgif.xsl sample on slide 18 from this WSTE webcast:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

    > 2) it seems the pgm1st.xsl is coded for a specific Content-Type (image/x-portable-greymap) and the messages I need to handle can be of any legitimate type(txt/pdf/jpg etc). How would I go about handling that variable for all types?
    >
    You can select by name alternatively, just query "dp:variable('var://local/attachment-manifest')", does not need to be by content type.

     
    Hermann<myXsltBlog/>
    Hi Hermann, Thanks for the response and in looking at those stylesheets I see where my problem lies. I'm using your pgm1st.xsl to parse the attachment manifest and fetch the attachment thru url-open smf in the Execution Trace of Binary Node I get a response of -1 instead of a 200. Here's the snippet of the pgms1st.xsl where I'm doing the url-open. Also, I'm attaching my attachment-manifest nodeset.

    <xsl:variable name="atthdrs" select="&ATTMAN;&ATTHDR;"/>
    <xsl:variable name="pgm1st" select="$atthdrs"/>
    <xsl:variable name="resp">
    <dp:url-open target="{$pgm1st/../uri}" response="binaryNode"/></xsl:variable>
    <xsl:variable name="encodedData" select="dp:binary-encode($resp/result/binary/node())"/>

    The Nodeset from the Execution Trace Response shows the following:

    <result>
    <binary>***BINARY NODE***</binary>
    <responsecode>-1</responsecode>
    </result>

    If it helps any, I'm using SoapUI to send SOAP messages with a jpg attachment to WSP hosting the wsdl I'm consuming.

    So, it seems that I'm still not fetching attachment from SOAP Message successfully thus not able to send via email. Thoughts
  • HermannSW
    HermannSW
    4903 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-03-01T11:00:32Z  
    Hi Hermann, Thanks for the response and in looking at those stylesheets I see where my problem lies. I'm using your pgm1st.xsl to parse the attachment manifest and fetch the attachment thru url-open smf in the Execution Trace of Binary Node I get a response of -1 instead of a 200. Here's the snippet of the pgms1st.xsl where I'm doing the url-open. Also, I'm attaching my attachment-manifest nodeset.

    <xsl:variable name="atthdrs" select="&ATTMAN;&ATTHDR;"/>
    <xsl:variable name="pgm1st" select="$atthdrs"/>
    <xsl:variable name="resp">
    <dp:url-open target="{$pgm1st/../uri}" response="binaryNode"/></xsl:variable>
    <xsl:variable name="encodedData" select="dp:binary-encode($resp/result/binary/node())"/>

    The Nodeset from the Execution Trace Response shows the following:

    <result>
    <binary>***BINARY NODE***</binary>
    <responsecode>-1</responsecode>
    </result>

    If it helps any, I'm using SoapUI to send SOAP messages with a jpg attachment to WSP hosting the wsdl I'm consuming.

    So, it seems that I'm still not fetching attachment from SOAP Message successfully thus not able to send via email. Thoughts
    Please post the content of "var://local/attachment-manifest" from your Probe here.
    In case you really send attachments it should look like shown here:
    https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14672215&#14672211

    Your "$pgm1st" will result in a node-set of all attachments.
    In case you really have attachments received (did you set Attachment Processing to "Allow"?),
    you may try to select the first attachment only by
    <xsl:variable name="pgm1st" select="$atthdrs[1]"/>

     
    Hermann<myXsltBlog/>
  • Daviiid
    Daviiid
    289 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-04-26T06:37:26Z  
    • HermannSW
    • ‏2012-03-01T11:00:32Z
    Please post the content of "var://local/attachment-manifest" from your Probe here.
    In case you really send attachments it should look like shown here:
    https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14672215&#14672211

    Your "$pgm1st" will result in a node-set of all attachments.
    In case you really have attachments received (did you set Attachment Processing to "Allow"?),
    you may try to select the first attachment only by
    <xsl:variable name="pgm1st" select="$atthdrs[1]"/>

     
    Hermann<myXsltBlog/>
    Hi Hermann

    Is it still impossible to send mail to multiple recipient?
  • HermannSW
    HermannSW
    4903 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-04-26T08:56:57Z  
    • Daviiid
    • ‏2012-04-26T06:37:26Z
    Hi Hermann

    Is it still impossible to send mail to multiple recipient?
    Hi Daviid,
    >
    > Is it still impossible to send mail to multiple recipient?
    >
    yes, from my above posting:

    > Sorry, that is not possible -- you can only specify one recipient:
    > http://publib.boulder.ibm.com/infocenter/wsdatap/4mt/index.jsp?topic=%2Fcom.ibm.dp.xb.doc%2Fextensionfunctions43.htm&resultof=%22url-open%22%20%22smtp%22
    >

    The reason is that a multiple dp:url-open's would be needed if you have CCs.
    The simplest workaround is to send to an electronic mailing list -- just define your CCs in a list, and the single dp:url-open() is sufficient.

    Since this is not in the product, adding CC support is a new feature and therefore will never happen on existing firmwares (3.8.0-4.0.2).

    Two days ago firmware V5.0 has been officially announced, but I am not aware that CC has been added:
    http://www-01.ibm.com/common/ssi/cgi-bin/ssialias?infotype=AN&subtype=CA&htmlfid=897/ENUS112-064&appname=USN

     
    Hermann<myXsltBlog/> <myXsltTweets/>
  • triniman10
    triniman10
    29 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-05-23T22:05:11Z  
    • HermannSW
    • ‏2012-02-28T14:38:54Z
    > ...
    > Of course, none of my xsl:message statements display anything which tells me I'm not converting them to text?
    If you can see "***BINARY NODE***" then you can use "dp:binary-encode(...)" to log the value base64 encoded to the log.
    That does work for any, also binary, data.

    > Also, I know I'm butchering extending your style sheets but can you shed light on a couple of actions I'm attempting to take here:
    > 1) how to read in the attachment from the binarynode to send via smtp
    See getgif.xsl sample on slide 18 from this WSTE webcast:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

    > 2) it seems the pgm1st.xsl is coded for a specific Content-Type (image/x-portable-greymap) and the messages I need to handle can be of any legitimate type(txt/pdf/jpg etc). How would I go about handling that variable for all types?
    >
    You can select by name alternatively, just query "dp:variable('var://local/attachment-manifest')", does not need to be by content type.

     
    Hermann<myXsltBlog/>
    Hi Hermann,
    I apologize for the delay between my posts/responses but I was pulled off on another project that took me away from the task of sending emails with attachments thru DataPower. Coincidently, I have another need for another project that requires DataPower to parse a digitally signed PDF and return it to a client as an XML populated by the parsed fields of the PDF. The PDF is a request form that will be posted from a Help Desk system. After going thru ur webcasts on Non-XML handling it looks like this is possible but seeing that I never got the emailing attachments to work, I'm in need of some more help with this task. The workflow is as follows:
    1) DP Accept Soap with Attachment type pdf.
    2) Parse PDF and build xml based on a schema with populated fields from PDF
    3) Call Web Service Operation to post XML to Web Service.

    Right now I'm testing it with XFW chained to a WSP where the XFW accepts the SwA and then after processing the pdf to xml calls the WSP endpoint for the necessary WS Operation to post data to web service.

    I appreciate your advice on what how to parse to PDF and populate XML accordingly. Thanks!
  • HermannSW
    HermannSW
    4903 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-05-24T10:40:27Z  
    Hi Hermann,
    I apologize for the delay between my posts/responses but I was pulled off on another project that took me away from the task of sending emails with attachments thru DataPower. Coincidently, I have another need for another project that requires DataPower to parse a digitally signed PDF and return it to a client as an XML populated by the parsed fields of the PDF. The PDF is a request form that will be posted from a Help Desk system. After going thru ur webcasts on Non-XML handling it looks like this is possible but seeing that I never got the emailing attachments to work, I'm in need of some more help with this task. The workflow is as follows:
    1) DP Accept Soap with Attachment type pdf.
    2) Parse PDF and build xml based on a schema with populated fields from PDF
    3) Call Web Service Operation to post XML to Web Service.

    Right now I'm testing it with XFW chained to a WSP where the XFW accepts the SwA and then after processing the pdf to xml calls the WSP endpoint for the necessary WS Operation to post data to web service.

    I appreciate your advice on what how to parse to PDF and populate XML accordingly. Thanks!
    Hi Burt,

    > 2) Parse PDF and build xml based on a schema with populated fields from PDF
    >
    that is a tough project, even when doing it in languages other than XSLT.

    PDF spec from Adobe is REALLY BIG, even the first version of the spec has 756 pages ...
    http://www.adobe.com/devnet/pdf/pdf_reference.html

    What I know form the past is, that nearly always binary data is present in PDF files.
    And sometimes even the complete page content is embedded as binary data which prevents reading anything without OCR software.

    If on the oher side "your" PDFs are more or less like "normal text" (some binary data in between does not hurt) you may be able to retrieve the field values.

    An alternative would be to extract the "application/pdf" type PDF by a fetch action from the SWA input file and send it to a webservice outside DataPower doing the XML field extraction
    (such a service would be able to make use of libraries for parsing PDF from Adobe).

     
    Hermann<myXsltBlog/> <myXsltTweets/>
  • triniman10
    triniman10
    29 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-05-24T20:38:45Z  
    • HermannSW
    • ‏2012-05-24T10:40:27Z
    Hi Burt,

    > 2) Parse PDF and build xml based on a schema with populated fields from PDF
    >
    that is a tough project, even when doing it in languages other than XSLT.

    PDF spec from Adobe is REALLY BIG, even the first version of the spec has 756 pages ...
    http://www.adobe.com/devnet/pdf/pdf_reference.html

    What I know form the past is, that nearly always binary data is present in PDF files.
    And sometimes even the complete page content is embedded as binary data which prevents reading anything without OCR software.

    If on the oher side "your" PDFs are more or less like "normal text" (some binary data in between does not hurt) you may be able to retrieve the field values.

    An alternative would be to extract the "application/pdf" type PDF by a fetch action from the SWA input file and send it to a webservice outside DataPower doing the XML field extraction
    (such a service would be able to make use of libraries for parsing PDF from Adobe).

     
    Hermann<myXsltBlog/> <myXsltTweets/>
    Thanks Hermann! One of our Unix Admins wrote a pl script to parse the binary and build an html page with certain values from the PDF. So, it seems that the effort to move that functionality to DataPower may be too great with our deadlines. Although, if you have a stylesheet example of what parsing a PDF with more or less normal text, I would love to take a look at it.

    v/r
    Burt
  • HermannSW
    HermannSW
    4903 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-05-24T20:44:33Z  
    Thanks Hermann! One of our Unix Admins wrote a pl script to parse the binary and build an html page with certain values from the PDF. So, it seems that the effort to move that functionality to DataPower may be too great with our deadlines. Although, if you have a stylesheet example of what parsing a PDF with more or less normal text, I would love to take a look at it.

    v/r
    Burt
    Please attach a small sample PDF with fields as in your target system.
    Then we can just look into and decide whether its doable or not.

     
    Hermann<myXsltBlog/> <myXsltTweets/>
  • triniman10
    triniman10
    29 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-05-24T21:58:18Z  
    • HermannSW
    • ‏2012-05-24T20:44:33Z
    Please attach a small sample PDF with fields as in your target system.
    Then we can just look into and decide whether its doable or not.

     
    Hermann<myXsltBlog/> <myXsltTweets/>
    I'll email it to you.
  • triniman10
    triniman10
    29 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-05-24T22:15:53Z  
    • HermannSW
    • ‏2012-05-24T20:44:33Z
    Please attach a small sample PDF with fields as in your target system.
    Then we can just look into and decide whether its doable or not.

     
    Hermann<myXsltBlog/> <myXsltTweets/>
    I just sent you an email with a sample xml and sample pdf. Please let me know when you received it. Thanks!
  • HermannSW
    HermannSW
    4903 Posts

    Re: Sending emails with DataPower appliance (X150 v4.1.0.4)

    ‏2012-05-24T23:44:15Z  
    I just sent you an email with a sample xml and sample pdf. Please let me know when you received it. Thanks!
    Hi Burt,

    I received your email -- and I am lost.
    I opened your form, just entered my name in "Name" field and saved that document.

    As you can see the difference is
    • quite big
    • and binary.

    I have no idea on how to extract the data from that -- perhaps a callout to your admin tool is best.



     
    Hermann<myXsltBlog/> <myXsltTweets/>