flask-study-005

本篇博客记录flask-mail的使用

from flask import Flask
from flask_mail import Mail, Message

app = Flask(__name__)

app.config['MAIL_SERVER'] = 'smtp.163.com'
app.config['MAIL_PORT'] = '465'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
app.config['MAIL_USERNAME'] = '[email protected]'
app.config['MAIL_PASSWORD'] = 'xxxxxxxxx' #邮箱服务器提供的授权码
mail = Mail(app)

@app.route('/sendmail')
def send_mail():
    msg = Message(subject="邮件测试", sender="[email protected]", recipients=['[email protected]'])
    msg.body = '验证码:111111'
    mail.send(msg)
    return "邮件发送成功"

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

浏览器访问:http://127.0.0.1:5000/sendmail

显示:邮件发送成功

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章