The problem
When you use flask-security registration, you get the following error:
mail = current_app.extensions.get('mail')
> mail.send(msg)
E AttributeError: 'NoneType' object has no attribute 'send'
../.pyenv/versions/3.7.0/envs/ipchronos/lib/python3.7/site-packages/flask_security/utils.py:401: AttributeError
Solution
Flask-security uses flask-mail to send emails. Since flask-mail is optional you get the previous error because you need to configure flask-mail:
First install it with:
pip install Flask-Mail
Then configure your flask app:
mail = Mail()
app = Flask(__name__)
mail.init_app(app)
Flask-Mail is configured through the standard Flask config API:
- MAIL_SERVER : default ‘localhost’
- MAIL_PORT : default 25
- MAIL_USE_TLS : default False
- MAIL_USE_SSL : default False
- MAIL_DEBUG : default app.debug
- MAIL_USERNAME : default None
- MAIL_PASSWORD : default None
- MAIL_DEFAULT_SENDER : default None
- MAIL_MAX_EMAILS : default None
- MAIL_SUPPRESS_SEND : default app.testing