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'] = 'liwldev@163.com'
app.config['MAIL_PASSWORD'] = 'xxxxxxxxx' #邮箱服务器提供的授权码
mail = Mail(app)
@app.route('/sendmail')
def send_mail():
msg = Message(subject="邮件测试", sender="liwldev@163.com", recipients=['18762673155@163.com'])
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
显示:邮件发送成功