QQ邮箱打开设置
打开STMP的设置
mail.py
把尖括号及其内部的内容都替换掉,<替换内容>
from flask import Flask
from flask_mail import Mail, Message
app = Flask(__name__)
app.config.update(
MAIL_SERVER='smtp.qq.com',
MAIL_PORT = 465,
MAIL_USE_SSL = True,
MAIL_USERNAME = '<自己的QQ号码>',
MAIL_PASSWORD = '<QQ授权码>'
)
mail = Mail(app)
@app.route('/')
def index():
msg = Message(subject="<邮件主题>",
sender='<发送者的邮箱>',
recipients=['<接收者的邮箱>'])
msg.html = "<h1>testing html</h1> <b>topic </b> 2 <这里是邮件的内容>"
mail.send(msg)
return "mail sent"
if __name__ == '__main__':
app.run(debug=True)
测试可以发送成功。