Good way to send mail from Python Scripts?
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
Hello Jean, Friday, September 14, 2001, 23:39:47, you wrote: .. [snip] ... JJ> 3. Now, unfortunately, the 'mailMessages' Python script won't have a JJ> 'REQUEST' of its own. In order to get hold of a 'REQUEST', wrap the JJ> Python script in another DTML method, and see to it that 'REQUEST' is JJ> included in the list of parameters for 'mailMessages'. JJ> 'mailMessagesWrapper':: JJ> <dtml-call mailMessages> JJ> I'm pretty sure this will trigger lots of good advice on what I could be JJ> doing better .. that would be most welcome. JJ> Regards, JJ> Jean You can easily get at the current REQUEST object in Pythonscripts using context.REQUEST :-) -- Geir Bækholt web-developer/zopatista geirh@funcom.com funcom oslo | webdev-team <!-- PGPid : 0x90B47B20 -->
participants (2)
-
Geir Bækholt -
Jean Jordaan