#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": 25,
    "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()


发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code