from flask import Flask
from flask_mail import Mail, Message
app = Flask(__name__)
app.config["MAIL_SERVER"] = " s m t p .163.com " 代理邮箱服务器的名字
app.config['MAIL_PORT'] = 465 #端口
app.config['MAIL_USE _ SSL'] = True
app.config['MAIL_USERNAME'] = "good study@163.com" #发送者的邮箱
app.config['MAIL_PASSWORD'] = " "#授权码
app.config['MAIL_DEFAULT_SENDER'] = 'Flask Admin <good study@163.com>'#默认的发送邮件的地址
mail = Mail(app)
@app.route('/')
def index():
return'<a h r e f="/send_mail">发送邮件</a>'
@app.route('/send_mail')
def send_mail():
message = Message('邮件主题', recipients=['good@163.com',])#发送给谁可以给多个邮箱进行发送 message.html="
<h>哈哈<h/>
"
mail.send(message)
return '发送中'
if __name__ == '__main__':
app.run(debug=True ,port=5001)