Flask-Mail

2020-01-19 11:21:18 浏览数 (1)

WOW! 我的大号QQ收到了小号QQ的邮件!

小玩Flask-Mail

先到小号邮箱开启服务并获取获取授权码  https://jingyan.baidu.com/article/b0b63dbf1b2ef54a49307054.html

接下来看看服务文档?重点关注:SSL或其他协议、服务器域名、端口、授权码。发邮件时记得不要把服务关掉!

 小试一下尝个鲜。

代码语言:javascript复制
#!/usr/bin/python
#coding=utf-8

from flask import Flask
    
from flask_mail import Mail, Message

app = Flask(__name__)

# 设置邮箱的配置信息
app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_SSL'] = True
app.config['MAIL_USERNAME'] = '小号111账号名'
app.config['MAIL_SERVER'] = 'smtp.qq.com'
app.config['MAIL_PASSWORD']  = '小号授权码' 

# 初始化邮箱实例
mail = Mail(app)


@app.route('/', )
def index():
    # 邮件消息对象
    msg = Message(
        "Hello",
        body="testing",
        sender="小号QQ@qq.com",
        recipients=["大号QQ@qq.com"]
    )
    # 发送邮件
    mail.send(msg)
    return "Send Success!"


if __name__ == '__main__':
    app.run(debug=True)

运行成功~

 官方:https://pythonhosted.org/Flask-Mail/

0 人点赞