7.1.修改邮箱界面完成
(1)cms/cms_resetemail.html
{% extends 'cms/cms_base.html' %} {% block title -%}
修改邮箱
{%- endblock %} {% block head %} {% endblock %} {% block page_title -%}
{{ self.title() }}
{%- endblock %} {% block main_content %} <form action="" method="post">
<div class="form-container">
<div class="form-group">
<div class="input-group">
<input type="email" name="email" placeholder="新邮箱" class="form-control">
<span class="input-group-addon">获取验证码</span>
</div>
</div>
<div class="form-group">
<div class="input-group">
<input type="text" name="captcha" placeholder="邮箱验证码" class="form-control">
</div>
</div>
<div class="form-group">
<button class="btn btn-primary" id="submit">立即修改</button>
</div>
</div> </form>
{% endblock %}
(2)cms.views.py
class ResetEmail(views.MethodView):
def get(self):
return render_template('cms/cms_resetemail.html') def post(self):
pass bp.add_url_rule('/resetemail/',view_func=ResetEmail.as_view('resetemail'))
(3)cms/cms_base.html
<li><a href="{{ url_for('cms.resetemail') }}">修改邮箱</a></li>
(3)static/cms/css/base.css
把cms_resetpwd.html中下面的样式放到base.css里面去,这样cms_resetemail和cms_resetpwd都可以用
.form-container{
width: 300px;
}
修改邮箱界面:
7.2.Flask-mail的使用以及邮箱的配置
(1)exts.py
from flask_mail import Mail mail = Mail()
(2)Perfect_bbs.py
from exts import db,mail mail.init_app(app)
(3)config.py
MAIL_SERVER = "SMTP.qq.com"
MAIL_PORT = ""
MAIL_USE_TLS = True
# MAIL_USE_SSL
MAIL_USERNAME = "1184405959@qq.com"
MAIL_PASSWORD = "zusbbabvfbdyqihxag"
MAIL_DEFAULT_SENDER = "1184405959@qq.com"
(4)cms/views.py
@bp.route('/email/')
def send_email():
#1.标题,2.收件人,3.发送的正文内容
message = Message(subject='derek论坛密码修改邮件发送',recipients=['1184405959@qq.com',],body='第一次测试发送邮件')
mail.send(message) #发送邮件
return '邮件发送成功'
测试功能,访问地址就会发送邮件:http://127.0.0.1:5000/cms/email/