1、安装
pip install Flask-Mail
2、配置
from flask_mail import Message, Mail
from flask import Flask
app = Flask(__name__)
app.config.update(
DEBUG=True,
MAIL_SERVER='smtp.163.com',#邮箱服务器
MAIL_PORT=465,#端口号
MAIL_USE_SSL=True,#支持ssl协议
MAIL_USERNAME='##',#邮箱账号
MAIL_PASSWORD='##'#授权码
)
mail = Mail(app=app)##创建邮箱对象
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/95eb419b504e9c7d9163322de0d8f60d.jpeg)
发送邮件
@app.route('/send')
def sendmail():
msg = Message(
subject='flask_test',
recipients=['###@qq.com'],#发送给谁
sender='<##@163.com>'#发送人
)
msg.html = '<h1>欢迎来到flask</h1>'
mail.send(msg)
return 'susseccful'
if __name__ == '__main__':
app.run()