[Zope] question on simple_send in MailHost

knitti knitti at gmail.com
Mon Jul 17 05:29:07 EDT 2006

On 7/17/06, John Schinnerer <john at eco-living.net> wrote:
> The Zope (2.7.5) API docs for MailHost show this for simple_send:
> --------------
> simple_send(self, mto, mfrom, subject, body):
>      Sends a message. Only To:, From: and Subject: headers can be set.
> The arguments are:
>      mto
>          A commaseparated string or list of recipient(s) of the message.
>      mfrom
>          The address of the message sender.
>      subject
>          The subject of the message.
>      body
>          The body of the message.
> --------------

a bit digging in the code on one of my installations (2.7.4) revealed,
that Zope more or less directly invokes  SMTP.sendmail from smtplib
of python. quote from the docs: "a list of RFC 822 to-address strings
(a bare string will be treated as a list with 1 address)"

this seems a small bug in zope (either implementation or
documentation). for a fix, make the list yourself:


this _could_ break the RFC-conformity of the to-header of the message,
because simple_send builds the body of the message like this:

body="From: %s\nTo: %s\nSubject: %s\n\n%s" \
        % (mfrom, mto, subject, body)

which would result in

To: ['me at mine.com','you at yours.com','him at his.com']

which makes the message unroutable.

I suggest this code for MailBase.simple_send() (Malhost.py):

import types # this belongs into the import section

[.. snip, in simple_send: ..]

def simple_send(self, mto, mfrom, subject, body):
    if type(mto)==types.ListType:
        body = "From: %s\nTo: %s\nSubject: %s\n\n%s" \
                % (mfrom, ','.join(mto), subject, body)
        body = "From: %s\nTo: %s\nSubject: %s\n\n%s" \
                % (mfrom, mto, subject, body)
    self._send(mfrom, mto, body)

and change the documentation to accept lists and strings,
because parsing a comma-separated list of true rfc-822
addresses is far more complicarted than somestring.split(',')


More information about the Zope mailing list