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

Jean Jordaan jean@upfrontsystems.co.za
Fri, 14 Sep 2001 23:39:47 +0200


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