Expose setting for sendmail failure alerts

This commit is contained in:
Lance Edgar 2022-08-07 18:45:45 -05:00
parent fe4c3d4942
commit 3413d7c6f6
2 changed files with 24 additions and 8 deletions

View file

@ -15,6 +15,15 @@
</b-checkbox> </b-checkbox>
</b-field> </b-field>
<b-field>
<b-checkbox name="rattail.mail.send_email_on_failure"
v-model="simpleSettings['rattail.mail.send_email_on_failure']"
native-value="true"
@input="settingsNeedSaved = true">
When sending an email fails, send another to report the failure
</b-checkbox>
</b-field>
</div> </div>
% if request.has_perm('errors.bogus'): % if request.has_perm('errors.bogus'):

View file

@ -34,6 +34,7 @@ import six
from rattail import mail from rattail import mail
from rattail.db import model from rattail.db import model
from rattail.config import parse_list from rattail.config import parse_list
from rattail.util import simple_error
import colander import colander
from deform import widget as dfwidget from deform import widget as dfwidget
@ -283,6 +284,9 @@ class EmailSettingView(MasterView):
{'section': 'rattail.mail', {'section': 'rattail.mail',
'option': 'record_attempts', 'option': 'record_attempts',
'type': bool}, 'type': bool},
{'section': 'rattail.mail',
'option': 'send_email_on_failure',
'type': bool},
] ]
def toggle_hidden(self): def toggle_hidden(self):
@ -414,11 +418,14 @@ class EmailPreview(View):
email = self.email_handler.get_email(key) email = self.email_handler.get_email(key)
data = email.obtain_sample_data(self.request) data = email.obtain_sample_data(self.request)
try:
self.email_handler.send_message(email, data, self.email_handler.send_message(email, data,
subject_prefix="[PREVIEW] ", subject_prefix="[PREVIEW] ",
to=[recipient], to=[recipient],
cc=None, bcc=None) cc=None, bcc=None)
except Exception as error:
self.request.session.flash(simple_error(error), 'error')
else:
self.request.session.flash( self.request.session.flash(
"Preview for '{}' was emailed to {}".format( "Preview for '{}' was emailed to {}".format(
key, recipient)) key, recipient))