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

顯示:郵件發送成功

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