使用QQ邮箱+stmplib发送邮件
in python with 0 comment

使用QQ邮箱+stmplib发送邮件

in python with 0 comment
  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) 
Responses