2017-07-18 12 views
0

メール送信に問題があります。電子メールから私はプログラムから得るが、私はそれをユーザーに送る。 BCCのメールアドレスが表示されます。私は答えを検索しましたが、ほとんどは、マルチアドレスではなく、CCやBCCアドレスpython送信者1人2 bcc

のために私は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() 

答えて

関連する問題