python-qq邮箱发送邮件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python-qq邮箱发送邮件相关的知识,希望对你有一定的参考价值。
可以试试,以后用在报错发邮件
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from email.header import Header
from email.mime.text import MIMETextimport smtplib
#username="[email protected]"
password = "授权码"
#授权码在QQ邮箱设置-账户下开通
from_addr = "[email protected]"
to_addr = "[email protected]"
smtp_server = "smtp.qq.com"
msg = MIMEText(‘hello, send by Python...‘, ‘plain‘, ‘utf-8‘)
msg[‘From‘] = Header("ppyy", ‘utf-8‘)
msg[‘To‘] = Header("you", ‘utf-8‘)
msg[‘Subject‘] = Header(‘来自SMTP的问候……‘, ‘utf-8‘)
try:
server = smtplib.SMTP_SSL(smtp_server,465)
#如果不是Qq smtp.qq.com改为localhost
server.login(from_addr, password)
server.sendmail(from_addr, to_addr,
msg.as_string())
server.quit()
print("success")
except smtplib.SMTPException:
print("unsuccess")
以上是关于python-qq邮箱发送邮件的主要内容,如果未能解决你的问题,请参考以下文章