使用python smtplib库发邮件添加cc,bcc详解编程语言

[Python]代码    

# -*- coding: cp936 -*- 
import smtplib 
from email.mime.text import MIMEText 
 
mail_host = 'smtp.126.com' 
mail_user = [email protected]' 
mail_pwd = 'hellopwd' 
mail_to = [email protected]' 
mail_cc = [email protected]' 
mail_bcc = [email protected]' 
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 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/8079.html

(0)
上一篇 2021年7月18日
下一篇 2021年7月18日

相关推荐

发表回复

登录后才能评论