From eb388ad04fa8a51193841a846dc0dec04b0d4f55 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Thu, 19 Jul 2012 17:05:06 -0400 Subject: [PATCH] Add RuntimeError to send_mail function --- flask_security/utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/flask_security/utils.py b/flask_security/utils.py index a1a1d0c..24a54b9 100644 --- a/flask_security/utils.py +++ b/flask_security/utils.py @@ -168,6 +168,14 @@ def send_mail(subject, recipient, template, context=None): :param template: The name of the email template :param context: The context to render the template with """ + mail = current_app.extensions.get('mail', None) + current_app.logger.debug('%s' % current_app.extensions) + + if mail is None: + raise RuntimeError('You need to install and configure the ' + 'Flask-Mail extension in order to send ' + 'emails with Flask-Security') + from flask.ext.mail import Message context = context or {} @@ -180,7 +188,7 @@ def send_mail(subject, recipient, template, context=None): msg.body = render_template('%s/%s.txt' % (base, template), **context) msg.html = render_template('%s/%s.html' % (base, template), **context) - current_app.mail.send(msg) + mail.send(msg) @contextmanager