2017-07-18 46 views
0

我有一個問題發送郵件。從我從程序中獲得的電子郵件,但是當我將它發送給用戶時。他們可以看到密件抄送電子郵件地址。我已經尋找一個答案,但大多是多地址,而不是CC或BCC地址python發送到1人和2密碼抄送

,所以我需要一個解決方案,將發送BCC但對用戶隱藏和BCC接收它們

def mail(self, email_user, to, subject, text, attach,attach2, email_pwd, smtp, port): 
    msg = email.MIMEMultipart.MIMEMultipart() 
    msg['From'] = email_user 
    msg['To'] = to # @newuser.be 
    msg['Bcc'] = "[email protected]" 
    msg['cc'] = "[email protected]" 
    msg['Subject'] = subject 
    part = MIMEText(text,'html') 
    #msg.attach(email.MIMEText.MIMEText(text)) 
    msg.attach(part) 
    if attach: 
     part = email.MIMEBase.MIMEBase('application', 'octet-stream') 
     part.set_payload(open(attach, 'rb').read()) 
     email.Encoders.encode_base64(part) 
     part.add_header('Content-Disposition','attachment; filename="%s"' % os.path.basename(attach)) 
     msg.attach(part) 
    if attach2: 
     part = email.MIMEBase.MIMEBase('application', 'octet-stream') 
     part.set_payload(open(attach2, 'rb').read()) 
     email.Encoders.encode_base64(part) 
     part.add_header('Content-Disposition','attachment; filename="%s"' % os.path.basename(attach2)) 
     msg.attach(part) 
    if(port != ""): 
     mailServer = smtplib.SMTP(smtp, port) 
    else: 
     mailServer = smtplib.SMTP(smtp) 

    mailServer.ehlo() 
    mailServer.starttls() 
    mailServer.ehlo() 
    mailServer.login(email_user, email_pwd) 
    mailServer.sendmail(email_user, to, msg.as_string()) 
    mailServer.close() 

回答

相關問題