Python编程:Flask扩展Flask-Mail发送邮件

版权声明:本文为博主原创文章,欢迎转载,请注明出处 https://blog.csdn.net/mouday/article/details/86701898

安装

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()

没有更多推荐了,返回首页