smtplib & Bcc
Steve Holden
sholden at holdenweb.com
Fri Feb 21 07:50:37 EST 2003
"Steven Taschuk" <staschuk at telusplanet.net> wrote in message
news:mailman.1045826579.14723.python-list at python.org...
> 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.)
>
You are also willing to pitch in and help someone else, which earns you
points in my book.
> 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.
>
Correct.
> (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.
>
Right so far. RFC821 = SMTP protocol, RFC822 = mail message format (nowadays
superseded by RFC2822, I believe).
> 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.
>
Well ...
> (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.)
>
I *believe* (and this isn't based on a reading of the RFCs, so shoot me down
if you like) that Bcc recipients of a message are simply not mentioned in
the headers. They get a copy, but there won't be a "Bcc:" header in the
message. This means that all handlers can just treat the message body as a
whole, without adding to it or subtracting from it. The fact that I got the
message without being mentioned in the "To:" or "Cc:" headers alerts me to
the fact that I am a Bcc recipient.
This is also a bit safer if the message is later forwarded via third parties
to recipients beyond your control ...
regards
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
Register for PyCon now! http://www.python.org/pycon/reg.html
More information about the Python-list
mailing list