邮箱模板渲染
Flask-Mail发送邮件
发送邮箱验证码
Redis保存邮箱验证码 验证码有效时间设置 60秒
config.py
打开QQ邮箱->设置->账户->点开启->获取密码->添加到config.py做邮箱配置
import os
HOSTNAME = '127.0.0.1'
DATABASE = 'bbs'
PORT = 3306
USERNAME = 'root'
PASSWORD = 'root'
DB_URL = 'mysql+mysqlconnector://{}:{}@{}:{}/{}?charset?'.format(USERNAME, PASSWORD, HOSTNAME, PORT, DATABASE)
SQLALCHEMY_DATABASE_URI = DB_URL
SQLALCHEMY_TRACK_MODIFICATIONS = False
SECRET_KEY = os.urandom(15)
# 发送邮箱的服务地址 QQ邮箱
MAIL_SERVER ='smtp.qq.com'
# 端口465或587
MAIL_PORT = '587'
MAIL_USE_TLS = True
# MAIL_USE_SSL = True 465
MAIL_USERNAME = '800588xx@qq.com'
# PASSWORD不是QQ密码
MAIL_PASSWORD = 'vpodrabovrqucafj'
MAIL_DEFAULT_SENDER = '800588xx@qq.com'
TEMPLATES_AUTO_RELOAD = True
cms_resetemail.html
{
% extends 'cms/cms_base.html' %}
{
% block title %}
修改邮箱
{
% endblock %}
{
% block page_title %}
{
{
self.title() }}
{
% endblock %}
{
% block head %}
<!--<style>-->
<!-- .form-container{
-->
<!-- width: 300px;-->
<!-- }-->
<!--</style>-->
<script src="{
{ url_for('static', filename='cms/js/resetemail.js') }}"></script>
{
% endblock%}
{
% block content %}
<form action="" method="post">
<div class="form-container">
<div class="form-group">
<div class="input-group">
<input type="email" class="form-control" name="email" placeholder="新邮箱">
<span class="input-group-addon" id="captcha-btn" style="cursor:pointer;">获取验证码</span>