BBS Forum (7)

BBS Forum (7)

7.1. Modification of the mailbox interface is complete

(1) cms/cms_resetemail.html

{% extends'cms/cms_base.html' %}

{% block title -%}
Modify email
{%- 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="new mailbox" class="form-control">
                    <span class="input-group-addon">Get verification code</span>
                </div>
            </div>
            <div class="form-group">
                <div class="input-group">
                    <input type="text" name="captcha" placeholder="E-mail verification code" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <button class="btn btn-primary" id="submit">Edit now</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') }}">Edit email</a></li>

(3) static/cms/css/base.css

Put the following styles in cms_resetpwd.html into base.css so that both cms_resetemail and cms_resetpwd can be used

.form-container{
    width: 300px;
}

Modify the mailbox interface:

7.2. The use of Flask-mail and the configuration of the mailbox

(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 = "587"
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. Title, 2. Recipient, 3. Text content sent
    message = Message(subject='derek forum password modification email sending', recipients=['1184405959@qq.com',], body='first test sending email')
    mail.send(message) #Send mail
    return'Mail sent successfully'

To test the function, an email will be sent to the access address: http://127.0.0.1:5000/cms/email/

Reference: https://cloud.tencent.com/developer/article/1390495 BBS Forum (7)-Cloud + Community-Tencent Cloud