smtplib & Bcc

Steven Taschuk staschuk at telusplanet.net
Fri Feb 21 07:26:18 EST 2003


Quoth Robin Becker:
  [...]
> I tried some simple experiments with Bcc: and cc: inside the message and
> it seems, when I send these using smtplib, that the cc list gets sent
> to, but the Bcc list receives no copy of the mail. Can some kind soul
> explain how we should use the Bcc header?

(Corrections to this explanation welcomed.  I know just enough to
*think* I know what I'm talking about.)

SMTP (RFC 821) is separate from message format (RFC 822).

A conversation between an SMTP client and server goes something
like this:  "Hi, I want to send some mail."  "Who to?"  "X, Y and
Z." "Okay, what's the message?"  "This is the message:
	To: X, Y
	Cc: Z

	Blah blah blah.
."  "Okay, mail sent."

Note that the client tells the server who to send mail to as part
of the protocol.  The server *doesn't* determine the recipients by
parsing the message content; it doesn't care what the message
content is.

(This allows SMTP to be used with arbitrary message formats.  It's
also why SMTP.sendmail() requires the sender and recipient
addresses as separate arguments, duplicating information which is
(usually) also in the headers.  Smtplib knows SMTP, but not
message formats.  Cf. the email package.)

So, it's up to the software that composes the message to set up
the headers as appropriate.  When you send an email using your
email client, it takes care of this for you, and the distinction
between RFCs 821 and 822 doesn't matter.  But if you're using
smtplib, thereby operating the SMTP layer directly, then you have
to do your own processing up front.

Typically you'd do something like this:  Gather up the To: and Cc:
recipients, compose a message with those headers, and send that to
those recipients (with one call to SMTP.sendmail()).  Then, for
each Bcc: recipient, compose a message with the To: and Cc:
headers, plus a Bcc: header naming the Bcc: recipient, and send
that to just that recipient.

(There's actually two possibilities if there's more than one Bcc:
recipient.  Either you send one message to them all, usually with
a Bcc: header naming all of them, or, as I said above, you send
each one their own message, each with a Bcc: header naming just
that one recipient.  Note that in the former case, all the Bcc:
recipients can see who was bcc'ed; they're only "blind" with
respect to the To: and Cc: recipients.  In the latter case, more
bandwidth is consumed, but none of the Bcc: recipients know who
the other Bcc: recipients were, if any.)

-- 
Steven Taschuk                               staschuk at telusplanet.net
"What I find most baffling about that song is that it was not a hit."
                            -- Tony Dylan Davis (CKUA)





More information about the Python-list mailing list