码迷,mamicode.com
首页 > 编程语言 > 详细

Python 使用其他邮件服务商的 SMTP 访问(QQ、网易、163、Google等)发送邮件

时间:2019-02-11 19:51:17      阅读:555      评论:0      收藏:0      [点我收藏+]

标签:googl   dma   UNC   xxx   邮箱   http   ror   archive   tps   

163邮箱SMTP授权

技术图片

 

使用Python SMTP发送邮件

# -*- coding:utf-8 -*-
from __future__ import print_function

__author__ = ‘yhwang‘
__version__ = ‘1.0‘


import smtplib
from email.mime.text import MIMEText
from email.header import Header


mail_host="smtp.163.com" 
mail_user="m13262578991@163.com" 
mail_pass="XXXXXX"
 
 
sender = ‘m13262578991@163.com‘
receivers = [‘1014080985@qq.com‘, ‘m13262578991@163.com‘]
 
message = MIMEText(‘Python 邮件发送测试...‘, ‘plain‘, ‘utf-8‘)
message[‘From‘] = Header("青蛙快飞", ‘utf-8‘)
message[‘To‘] =  Header("测试", ‘utf-8‘)
 
subject = ‘Python SMTP 邮件测试‘
message[‘Subject‘] = Header(subject, ‘utf-8‘)
 
for receiver in receivers:
    try:
        smtpObj = smtplib.SMTP_SSL(mail_host, port=465) 
        smtpObj.login(mail_user, mail_pass)
        smtpObj.sendmail(sender, receiver, message.as_string())
        smtpObj.quit() 
        print(u"%s邮件发送成功" % receiver)
    except smtplib.SMTPException:
        print(u"Error: 发送%s邮件失败" % receiver)

 

 

参考资料

https://www.cnblogs.com/xiaowuyi/archive/2012/03/17/2404015.html

Python 使用其他邮件服务商的 SMTP 访问(QQ、网易、163、Google等)发送邮件

标签:googl   dma   UNC   xxx   邮箱   http   ror   archive   tps   

原文地址:https://www.cnblogs.com/yahengwang/p/10362904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!