From c51c02481bb5ed9d40451372afcb34d0ab4f56a6 Mon Sep 17 00:00:00 2001 From: Feth AREZKI Date: Mon, 20 Feb 2012 17:03:44 +0100 Subject: [PATCH] tolerance to smtp error when creating project --- budget/web.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/budget/web.py b/budget/web.py index c3736d3..b8ae71d 100644 --- a/budget/web.py +++ b/budget/web.py @@ -3,6 +3,7 @@ from collections import defaultdict from flask import * from flaskext.mail import Mail, Message from flaskext.babel import get_locale, gettext as _ +from smtplib import SMTPRecipientsRefused import werkzeug # local modules @@ -142,10 +143,17 @@ def create_project(): msg = Message(message_title, body=message_body, recipients=[project.contact_email]) - mail.send(msg) + try: + mail.send(msg) + except SMTPRecipientsRefused: + msg_compl = 'Problem sending mail. ' + # TODO: destroy the project and cancel instead? + else: + msg_compl = '' # redirect the user to the next step (invite) - flash(_("The project identifier is %(project)s", project=project.id)) + flash(_("%(msg_compl)sThe project identifier is %(project)s", + msg_compl=msg_compl, project=project.id)) return redirect(url_for(".invite", project_id=project.id)) return render_template("create_project.html", form=form)