I need for testing purposes to populate few hundred email boxes with various messages, and was going to use smtplib for that. But among other things I need to be able to send messages not only TO specific mailboxes, but CC and BCC them as well. It does not look like smtplib supports CC-ing and BCC-ing while sending emails.
Looking for suggestions how to do CC or BCC sending messages from the python script.
(And — no, I'm not creating a script to spam anyone outside of my testing environment.)
Key thing is to add the recipients as a list of email ids in your sendmail call.
Don't add the bcc header.
See this: http://mail.python.org/pipermail/email-sig/2004-September/000151.html
And this: """Notice that the second argument to sendmail(), the recipients, is passed as a list. You can include any number of addresses in the list to have the message delivered to each of them in turn. Since the envelope information is separate from the message headers, you can even BCC someone by including them in the method argument but not in the message header.""" from http://pymotw.com/2/smtplib
It did not worked for me until i created:
and than added cc in recipient [list] like:
Email headers don't matter to the smtp server. Just add the CC and BCC recipients to the toaddrs when you send your email. For CC, add them to the CC header.
You can try MIMEText
then send msg.as_string()
http://docs.python.org/library/email-examples.html
The distinction between TO, CC and BCC occurs only in the text headers. At the SMTP level, everybody is a recipient.
TO - There is a TO: header with this recipient's address
CC - There is a CC: header with this recipient's address
BCC - This recipient isn't mentioned in the headers at all, but is still a recipient.
If you have
You have three recipients. The headers in the email body will include only the TO: and CC: