安装
pip install Flask-Mail
代码示例
from flask import Flask from flask_mail import Mail, Message app = Flask(__name__) mail_config = { "MAIL_SERVER": "smtp.163.com", "MAIL_PORT": 465, "MAIL_USE_SSL": True, "MAIL_USERNAME": "xxxxx@163.com", "MAIL_PASSWORD": "123456" } app.config.update(mail_config) mail = Mail(app) @app.route("/send_mail") def send_mail(): """ 发送邮件 """ message = Message("标题", sender=app.config["USERNAME"], recipients=["xxxxxx@qq.com"]) message.body = "内容" mail.send(message) return "发送成功" if __name__ == "__main__": app.run()