Handle email errors in a better manner
This commit is contained in:
parent
793b6f543c
commit
93cd7de0e0
3 changed files with 19 additions and 3 deletions
|
@ -1,3 +1,6 @@
|
|||
import logging
|
||||
import traceback
|
||||
|
||||
from flask.ext.mail import Message
|
||||
|
||||
from app import mail, app, get_app_url
|
||||
|
@ -5,8 +8,12 @@ from data import model
|
|||
from util.gravatar import compute_hash
|
||||
from util.jinjautil import get_template_env
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
template_env = get_template_env("emails")
|
||||
|
||||
class CannotSendEmailException(Exception):
|
||||
pass
|
||||
|
||||
def send_email(recipient, subject, template_file, parameters):
|
||||
app_title = app.config['REGISTRY_TITLE_SHORT']
|
||||
app_url = get_app_url()
|
||||
|
@ -30,8 +37,11 @@ def send_email(recipient, subject, template_file, parameters):
|
|||
|
||||
msg = Message('[%s] %s' % (app_title, subject), recipients=[recipient])
|
||||
msg.html = rendered_html
|
||||
mail.send(msg)
|
||||
|
||||
try:
|
||||
mail.send(msg)
|
||||
except Exception as ex:
|
||||
raise CannotSendEmailException(ex.message)
|
||||
|
||||
def send_password_changed(username, email):
|
||||
send_email(email, 'Account password changed', 'passwordchanged', {
|
||||
|
|
Reference in a new issue