from flask import Flask标签:__,flask,app,发送,Flask,msg,MAIL,config,邮件 From: https://www.cnblogs.com/kongzhagen/p/16849025.html
from flask_mail import Mail, Message
from flask import current_app, render_template
app = Flask(__name__)
app.config['MAIL_SERVER'] = 'smtp.qq.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = '[email protected]'
app.config['MAIL_PASSWORD'] = 'xxxx'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(app)
with app.app_context():
msg = Message('Hello', sender=app.config['MAIL_USERNAME'],
recipients=['[email protected]'])
msg.body = "Hello Flask message sent from Flask-Mail"
mail.send(msg)
@app.route("/")
def index():
msg = Message('Hello', sender=app.config['MAIL_USERNAME'],
recipients=['[email protected]'])
msg.body = "Hello Flask message sent from Flask-Mail"
msg.html = "This is <b>HTML</b>"
mail.send(msg)
return "Sent"
if __name__ == '__main__':
app.run(debug=True)