0

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

y0657bys 10年前发布 | 5K 次阅读 Python

[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
本文由用户 y0657bys 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!

AltStyle によって変換されたページ (->オリジナル) /