pallets-eco/flask-mail

After move system to blueprints I get error when sending mail

Closed this issue · 1 comments

ivall commented

Hello, in main file all works fine, but after move all system of sending messages to blueprint I getting error: KeyError: 'mail'
My initting app in blueprint code:

from flask import Flask, request, session, url_for, redirect, flash
from flask_mysqldb import MySQL
from flask import Blueprint
from flask_mail import Mail, Message
from itsdangerous import URLSafeTimedSerializer, SignatureExpired
import string
import bcrypt
import random

forget_password_blueprint = Blueprint('forget_password_blueprint', __name__)

app = Flask(__name__)
app.config.from_object('config')
mysql = MySQL(app)
mail = Mail(app)
mail.init_app(app)

s = URLSafeTimedSerializer('secretkey')

Sending email code:

            token = s.dumps(email, salt='password-reset')
            msg = Message('mikroblog.ct8.pl: resetuj hasło', sender='mikroblog@ivall.pl', recipients=[email])
            link = url_for('forget_password_blueprint.reset_token', token=token, _external=True)
            msg.body = 'Otrzymano prośbę o zresetowanie hasła do serwisu https://mikroblog.ct8.pl, link do resetowania hasła: {}'.format(
                link)
            mail.send(msg)
ivall commented

Fixed, idk how.