使用QQ邮箱+stmplib发送邮件


  1. 获取qq邮箱授权码
    什么是授权码,如何设置
  1. 代码
import smtplib
from email.mime.text import MIMEText
user = "你的qq邮箱"
pwd  = "你的授权码"
to   = "要发送的邮箱"

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

try:
    s = smtplib.SMTP_SSL("smtp.qq.com", 465)
    s.login(_user, pwd)
    s.sendmail(_user, _to, msg.as_string())
    s.quit()
    print("发送成功")
except smtplib.SMTPException,e: 
    print ("失败,%s" %e) 

声明:coder-syl|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - 使用QQ邮箱+stmplib发送邮件


Carpe Diem and Do what I like