[Zope] Mail from python script
Evan Simpson
evan@4-am.com
Sun, 07 Jul 2002 19:58:00 -0500
Brian Sullivan wrote:
> I am attempting to send mail ( using Zope 2.5.1 on Win2000) from python
> using the following code found at Zopelab.com:
>
> mailhost=getattr(context, context.superValues('Mail Host')[0].id)
> mailhost.send('Test', 'root@coursesbywire.com',
> 'root@coursesbywire.com', 'Test')
>
> Using DTML sendmail tag seems to work without a hitch but the mail
> server rejects the Python script generated email with the following
> error info:
>
>
> Reason: Message headers exceed xxx bytes.
> Headers are probably not formed correctly.
You may want to use this instead:
mailhost=context.superValues('Mail Host')[0]
mailhost.send('Subject: Test\n\nTest', 'root@coursesbywire.com',
'root@coursesbywire.com')
..or even...
mailhost=context.superValues('Mail Host')[0]
mailhost.send('''\
From: root@coursesbywire.com
To: root@coursesbywire.com
Subject: Test
Test''')
The 'send' method tries to read header lines from the body text, and may
be responsible for your error message. The 'getattr(...' indirection is
pointless, as far as I can tell.
Cheers,
Evan @ 4-am