使用python smtplib库发邮件添加cc,bcc,smtplibbcc,[Python]代码#


[Python]代码

# -*- coding: cp936 -*-# 甄码农,20120307import smtplibfrom email.mime.text import MIMETextmail_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_usermsg['Subject'] = 'this is a python test mail'msg['To'] = mail_tomsg['Cc'] = mail_ccmsg['Bcc'] = mail_bcctry:    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

评论关闭