| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
y0657bys
9年前发布

使用python smtplib库发邮件添加cc,bcc

[Python]代码    

# -*- coding: cp936 -*-  import smtplib  from email.mime.text import MIMEText    mail_host = 'smtp.126.com'  mail_user = 'xxx@126.com'  mail_pwd = 'hellopwd'  mail_to = 'xxao@gmail.com'  mail_cc = 'xx@xx.com'  mail_bcc = 'xx@qq.com'  content = 'this is a mail sent with python'    #表头信息  msg = MIMEText(content)  msg['From'] = mail_user  msg['Subject'] = 'this is a python test mail'  msg['To'] = mail_to  msg['Cc'] = mail_cc  msg['Bcc'] = mail_bcc  try:      s = smtplib.SMTP()      s.connect(mail_host)      #login      s.login(mail_user,mail_pwd)        #send mail      s.sendmail(mail_user,[mail_to,mail_cc,mail_bcc],msg.as_string())      s.close()      print 'success'  except Exception ,e:      print e