廢話不多說,直接上代碼:
from flask import Flaskfrom
flask_mail import Mail, Message
app = Flask(__name__)
app.config.update(?
? ? ? #EMAIL SETTINGS?
? ? MAIL_SERVER='smtp.qq.com',?
? ? MAIL_PORT=465,?
? ? MAIL_USE_SSL=True,?
? ? MAIL_USERNAME = 'qq號(hào)(如:123456)',?
? ? MAIL_PASSWORD = 'qq郵箱授權(quán)碼'? ? )

mail = Mail(app)
@app.route("/")
def index():?
? ? msg = Message(subject="helloworld", sender='發(fā)送郵箱地址(如:123456@qq.com)', recipients=['接受郵箱地址(如:654321@qq.com)'])? ?
? ? msg.html = "testinghtml"?
? ? mail.send(msg)?
if__name__ =='__main__':
? ? app.run(debug=True)