STMP, mail, sender-from, to-bcc-addr

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Tue Feb 10 16:39:56 CET 2009


durumdara schreef:
> Hi!
> 
> I wanna ask that have anyone some experience with email.msg and smtplib?
> 
> The email message and smtp.send already have "sender/from" and 
> "recip/addr to".
> Possible the smtp components does not uses the email tags if I not 
> define them only in the message?

smtplib.SMTP.sendmail() does not look in the message to find the sender
or recipients; it only uses the parameters you pass.

> Can I do same thing as in GMAIL that the mail does not have TO, only BCC 
> tags/recipients, and no one of the recipients who knows about the each 
> others?

Include the BCC-recipients in the call to sendmail(), but don't put them
in the email message itself. Include TO-recipients in both. In other
words, what you put in the TO-header is what all recipients will see;
what you pass to sendmail() is what recipients the mail will be send to.
Simple example (not tested):

from_addr = 'foo at example.com'
to_addr = ['bar at example.com', 'xyzzy at example.com']
bcc_addr = ['spam at example.com', 'eggs at example.com']

msg = """From: %s
To: %s
Subject: test

hello
""" % (from_addr, ', '.join(to_addr))

smtp = smtplib.SMTP(...)
smtp.sendmail(from_addr, to_addr + bcc_addr, msg)


-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

Roel Schroeven



More information about the Python-list mailing list