0

This works OK, EXCEPT that the Bcc email addresses are not hidden. How do I hide them?

Edit: This question appears to have been asked before, but none of the answers specifically anwswer the question of why the the Bcc'd email addresses are not hidden, even though they are delivered correctly.

from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import smtplib

msg = MIMEMultipart()
msg["Subject"] = "Example"
msg["From"] = "me@example.com"
msg["To"] = "undisclosed@example.com"
msg["Bcc"] = "hidden1@example.com, hidden2@example.com"
body = MIMEText("example email body")
msg.attach(body)
smtp = smtplib.SMTP("mailhost.example.com", 25)
smtp.sendmail( msg['From'], [ msg['To'], msg['Bcc'] ], msg.as_string() )
smtp.quit()
ruana
  • 1
  • 1
  • 2
  • This is not a duplicate and the question was not answered before. I've done an exhaustive search and could not find a solution as to why the Bcc email addresses are not hidden. – ruana Oct 09 '15 at 19:11
  • 1
    If you put anything into the headers, it's part of the message and is being delivered to everybody. bcc is something the mail program has to tell the mail daemon/service by different means: Usually as a command line argument – cfi Oct 09 '15 at 20:29

1 Answers1

0

smtplib doesn't include any headers automatically you must explicitly create them.

header = 'To:' + to + '\n' + 'From: ' + user + '\n' + 'Subject:testing \n'
IamK
  • 2,753
  • 5
  • 30
  • 39