基于python3+smtlib库,发送email
import smtplib
from email.mime.text import MIMEText
from email.header import Header
# 第三方 SMTP 服务
mail_host="smtp.exmail.qq.com" #设置服务器
mail_user="lizhihai@xxxx.cn" #用户名
mail_pass="xxxxx" #口令
sender = 'lizhihai@xxxx.cn'
receivers = ['anyuanlzh@xxx.com']
message = MIMEText('Python 邮件发送测试...', 'plain', 'utf-8')
message['From'] = Header("Python邮件", 'utf-8')
message['To'] = Header("测试", 'utf-8')
subject = 'Python SMTP 邮件测试'
message['Subject'] = Header(subject, 'utf-8')
try:
smtpObj = smtplib.SMTP_SSL(mail_host, 465)
smtpObj.login(mail_user,mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print ("邮件发送成功")
except smtplib.SMTPException:
print ("Error: 无法发送邮件")
更详细参考:https://zhuanlan.zhihu.com/p/318387004