使用Flask-Mail发送QQ邮件

#coding:utf-8
import os
from flask import Flask
from flask_mail import Mail
from flask_script import Manager
app = Flask(__name__)
manager = Manager(app)

app.config['MAIL_SERVER'] = 'smtp.qq.com'
app.config['MAIL_PORT'] = 25
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_PASSWORD'] = '授权码'
app.config['MAIL_USERNAME'] = '[email protected]'

mail = Mail(app)

if __name__ == '__main__':
    manager.run()
    #app.run()


使用Flask-Mail发送QQ邮件_第1张图片

在终端中运行:"python 文件名.py shell "

from flask_mail import Message
from mail_1 import mail
msg = Message('test subject', sender='[email protected]', recipients=['[email protected]'])
msg.body = 'text body'
msg.html = 'HTML body'
with app.app_context():
  mail.send(msg)


你可能感兴趣的:(Flask,人工智能论文解读与开发技术分享)