日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Flask发送邮件,最基础

發(fā)布時間:2025/5/22 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Flask发送邮件,最基础 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
首先要開啟自己郵箱的 smtp 服務(wù),并且開啟 smtp 服務(wù)端口

例如 QQ 郵箱 :

  • 打開設(shè)置
  • 點擊賬戶
  • 開啟smtp
  • 獲取安全密鑰

在templates 下,建個郵件樣式存儲目錄 mail
  • 新建個 find.html
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Test</title> </head> <body><h1>測試成功</h1> </body> </html>
  • 新建個 find.txt
我是 txt ,隨便寫點什么吧

在 app 中 :

from flask import Flask,render_template from flask_mail import Mail,Messageapp = Flask(__name__)app.config['MAIL_SERVER'] = '' # 填自己郵箱的服務(wù) eg : smtp.163.com app.config['MAIL_USERNAME'] = '' # 發(fā)送者的郵箱 app.config['MAIL_PASSWORD'] = '' # 自己郵箱 smtp 的安全密鑰不是郵箱的登錄密碼mail = Mail(app)def async_send_mail(mail):mail.send(message=msg)@app.route("/") def hello_world():# 主題 發(fā)給誰 列表(同時發(fā)送多個人) 誰發(fā)的msg = Message(subject='找回密碼',recipients=['自收件人郵箱地址'],sender=app.config['MAIL_USERNAME'])msg.html = render_template('mail/find.html')# 郵件內(nèi)容msg.body = render_template(('mail/find.txt'))mail.send(msg)return '已經(jīng)發(fā)送'if __name__ == "__main__":app.run(debug=True)

總結(jié)

以上是生活随笔為你收集整理的Flask发送邮件,最基础的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。