Python 使用其他邮件服务商的 SMTP 访问(QQ网易163Google等)发送邮件
Posted yahengwang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 使用其他邮件服务商的 SMTP 访问(QQ网易163Google等)发送邮件相关的知识,希望对你有一定的参考价值。
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="[email protected]" mail_pass="XXXXXX" sender = ‘[email protected]‘ receivers = [‘[email protected]‘, ‘[email protected]‘] 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网易163Google等)发送邮件的主要内容,如果未能解决你的问题,请参考以下文章