Server.sendmail with no "to_addrs" parameter.

Tim Roberts timr at
Thu Mar 23 09:33:29 CET 2006

"EdWhyatt" <ed.whyatt at> wrote:
>Ok, totally unrelated, and on that subject, I will make sure I always
>have a recipient in the To: field. - hey it works if I do that anyway!

OK, I'm a bit concerned that the answer to the original question has been
lost.  The difference between the SMTP envelope and the message content is
an important one, and that's the key point here.  If this is obvious to
everyone involved, I apologize.

The actual content of an e-mail message, including the message headers, has
absolute nothing to do with the delivery of the message.  That's all just a
convention that we have developed to allow messages to be read by humans.
All of the To:, Cc:, and Bcc: headers are there for you, the human (well,
and your helper, the e-mail reader).  SMTP doesn't care one whit about

The smtplib.sendmail method has three parameters: sender, recipient list,
and content.  SMTP could not care less about the content.  You can skip ALL
of the headers (as long as you leave a blank line), and it will be
delivered just fine.  It won't be RFC 822 compliant, but SMTP doesn't care.
SMTP is RFC 821.  Your message will get delivered, although the recipients
e-mail reader might croak on it.

SMTP cares about the sender and the recipient list.  Going off the deep
end, consider this Python snippet:

   msg = """\
To: noone at
Subject: This is the RFC-822 part

Hello, mom!"""

   s = smtplib.SMTP('localhost')
   s.sendmail( "tim at", ["one at","two at"], msg )

Note that the To: address is not listed in the sendmail parameters.  Now,
here is a "simulated" SMTP script for this message:

    MAIL FROM: <timr at>
    RCPT TO: <one at>
    RCPT TO: <two at>
    To: noone at
    Subject: This is the RFC-822 part

    Hello, mom!

Those first four commands are SMTP, generated from the first two parameters
to sendmail, and those are the ONLY things that determine where this
message will be delivered.  The are called the "envelope".  Note that the
actual recipients' names do not appear in the message body AT ALL.  At the
other end, Mr. One at Foo, Inc., might be surprised to receive a message
that does not appear to have been addressed to him, but SMTP doesn't care.

So, the way a BCC works is that the address goes into the envelope (in the
to_addrs list), but not in the message body.
- Tim Roberts, timr at
  Providenza & Boekelheide, Inc.

More information about the Python-list mailing list