[Zope] Good way to send mail from Python Scripts?

complaw@hal-pc.org complaw@hal-pc.org
Fri, 14 Sep 2001 22:24:24 GMT


There is a good demo of sending mail on the ZopeLabs site
(http://www.zopelabs.com).

See specifically:

http://www.zopelabs.com/cookbook/991178206

HTH,

Ron

> Hi Zopers
> 
> In my experience, it's tricky to send mail from Python Scripts. 
> Here's how I'm doing it at the moment.
> 
> 1. Have a DTML method which does the mailing. This method should 
>    have the 'Manager' proxy role (or a role which is allowed to 
>    access your 'MailHost'). 
> 
>    'mailMessage'::
> 
>     <dtml-try>
>     <dtml-sendmail ...>
>     text text text 
>     </dtml-sendmail>
>     </dtml-try>
> 
> 2. Have a Python script which calls 'mailMessage'.
> 
>    'mailMessages'::
> 
>     # Lots of intricate logic which would be painful in DTML ...
>     for this in these:
>         container.mailMessage( container
>                              , REQUEST, _
>                              , address=this.address
>                              )
> 
>    Note that 'mailMessage' is unhappy if it is called without DTML
>    namespace (? check this) and 'REQUEST'. 
> 
> 3. Now, unfortunately, the 'mailMessages' Python script won't have a
>    'REQUEST' of its own. In order to get hold of a 'REQUEST', wrap the
>    Python script in another DTML method, and see to it that 'REQUEST' is
>    included in the list of parameters for 'mailMessages'.
> 
>    'mailMessagesWrapper'::
> 
>     <dtml-call mailMessages>
> 
> I'm pretty sure this will trigger lots of good advice on what I could be
> doing better .. that would be most welcome.
> 
> Regards,
> Jean
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>