send email with bcc

Ed akegb3 at
Fri Nov 30 21:25:37 CET 2012


I have found many different suggestions on "how to" code python to send a bcc email. None of which have worked in my environment - yet. Following is what I have at this time, which is erroring. Most of the code I've found will successfully send the message to the TO & CC recipients, but not the BCC. Any help is very much appreciated. Thx, Ed <Python novice>.

from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from smtplib import SMTP

to = 'ed at'
cc = 'ed at'
bcc = 'ed at'
sender = 'edsboss at'

msg = MIMEMultipart()
msg['To'] = to
msg['Cc'] = cc
msg['Subject'] = 'Monthly Report'
msg['From'] = sender

smtp = SMTP("")
# Start the server:

# Send the email
smtp.sendmail(sender, [to] + bcc, msg.as_string())

The above generates the following error:
Traceback (most recent call last):
  File "/opt/batch/ebtest/", line 46, in <module>
    smtp.sendmail(sender, [to] + bcc, msg.as_string())

Other iterations of the code have worked without error, but do not send mail to the BCC recipient.

Thanks in advance for any assistance!

More information about the Python-list mailing list