From 3413d7c6f6b2afda438d0c4007c89450912dd70f Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 7 Aug 2022 18:45:45 -0500 Subject: [PATCH] Expose setting for sendmail failure alerts --- .../templates/settings/email/configure.mako | 9 ++++++++ tailbone/views/email.py | 23 ++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tailbone/templates/settings/email/configure.mako b/tailbone/templates/settings/email/configure.mako index 31da4f8e..13bceb3e 100644 --- a/tailbone/templates/settings/email/configure.mako +++ b/tailbone/templates/settings/email/configure.mako @@ -15,6 +15,15 @@ + + + When sending an email fails, send another to report the failure + + + % if request.has_perm('errors.bogus'): diff --git a/tailbone/views/email.py b/tailbone/views/email.py index 3798639a..d381907d 100644 --- a/tailbone/views/email.py +++ b/tailbone/views/email.py @@ -34,6 +34,7 @@ import six from rattail import mail from rattail.db import model from rattail.config import parse_list +from rattail.util import simple_error import colander from deform import widget as dfwidget @@ -283,6 +284,9 @@ class EmailSettingView(MasterView): {'section': 'rattail.mail', 'option': 'record_attempts', 'type': bool}, + {'section': 'rattail.mail', + 'option': 'send_email_on_failure', + 'type': bool}, ] def toggle_hidden(self): @@ -414,14 +418,17 @@ class EmailPreview(View): email = self.email_handler.get_email(key) data = email.obtain_sample_data(self.request) - self.email_handler.send_message(email, data, - subject_prefix="[PREVIEW] ", - to=[recipient], - cc=None, bcc=None) - - self.request.session.flash( - "Preview for '{}' was emailed to {}".format( - key, recipient)) + try: + self.email_handler.send_message(email, data, + subject_prefix="[PREVIEW] ", + to=[recipient], + cc=None, bcc=None) + except Exception as error: + self.request.session.flash(simple_error(error), 'error') + else: + self.request.session.flash( + "Preview for '{}' was emailed to {}".format( + key, recipient)) def preview_template(self, key, type_): email = self.email_handler.get_email(key)