1.设置

需要先去qq邮箱后台设置,打开POP3/SMTP,还要生成授权码,就是下面代码中填的密码。MIMEText支持html

Python QQ 发送Email SMTP_qq邮箱


import smtplib

from email.mime.text import MIMEText
_user = "XXX@qq.com"
_pwd = "XXXX"
_to = "XXX@qq.com"

msg = MIMEText("Test")
msg["Subject"] = "don't panic"
msg["From"] = _user
msg["To"] = _to


s = smtplib.SMTP_SSL("smtp.qq.com", 465)
s.login(_user, _pwd)
s.sendmail(_user, _to, msg.as_string())
s.quit()




SMTP_SSL 用这个初始化,端口传465