[Zope] dtml-sendmail gotcha

Tres Seaver tseaver@palladion.com
Thu, 20 Jan 2000 17:42:39 -0600


Donald G Porter <dgp@cam.nist.gov> wrote:
> 
> Here's a challenge.  What's wrong with the following DTML snippet?
> 
> <dtml-sendmail mailhost="MailHost">
> To: <dtml-var email>
> From: Example.Net <WebStaff@example.net>
> Subject: Joining Example.Net
> 
> To complete your registration with Example.Net (blah blah...)
> 
> </dtml-sendmail>
> 
> On my Zope site I had a similar DTML snippet, and it refused to
> send the mail message, but it also gave no error message that I
> could see, so debugging it took a ***long*** time.  Do you see
> the problem?
> 
> Here's what worked for me:
> 
> <dtml-sendmail mailhost="MailHost">
> To: <dtml-var email>
> From: "Example.Net" <WebStaff@example.net>
> Subject: Joining Example.Net
> 
> To complete your registration with Example.Net ...
> 
> </dtml-sendmail>
> 
> Those double quotes can make a world of difference.  I'm posting this
> to the Zope mailing list in the hope that it will keep others out
> of this blind alley which cost me so much time and frustration.  Good
> thing my site is for fun and not for profit!

I have another fun one for you.  Imagine a ZClass which sends e-mail
automagically as its state changes, and embeds attributes like its id and title
in the mail.  The DTML method which sends the mail looks like::

 <dtml-sendmail mailhost=MailHost>
 From: Zope Guru of the Week <ZGotW@palladion.com>
 To: <dtml-var "_.string.join( toAddressList, ',' )">
 Cc: <dtml-var "_.string.join( ccAddressList, ',' )">
 Subject: [ZGotW] Issue #<dtml-var id> (<dtml-var status>)
 Date: <dtml-var ZopeTime>
 
 <!-- The following method uses title and absolute_url -->
 <dtml-var issue_txt>
 
 </dtml-sendmail>
 </dtml-let>

The sendmail tag seems to push the MailHost onto the top of the acquisition
stack, so that id, title, and absolute_url now render via the folder containing
the MailHost, rather than the ZClass instance whose method is being called!

The fix is to externalize the values before entering the sendmail tag::

 <dtml-let issueID=id
           issueURL=absolute_url
           issueTitle=title>
 <dtml-sendmail mailhost=MailHost>
 From: Zope Guru of the Week <ZGotW@palladion.com>
 To: <dtml-var "_.string.join( toAddressList, ',' )">
 Cc: <dtml-var "_.string.join( ccAddressList, ',' )">
 Subject: [ZGotW] Issue #<dtml-var issueID> (<dtml-var status>)
 Date: <dtml-var ZopeTime>
 
 <dtml-var "issue_txt( _.None, _
                     , issueTitle=issueTitle
                     , issueURL=issueURL )">
 
 </dtml-sendmail>
 </dtml-let>

Ugh!
-- 
=========================================================
Tres Seaver         tseaver@palladion.com    713-523-6582
Palladion Software  http://www.palladion.com