Expose basic way to send test email

most of the mechanics of sending email could already be tested by
sending a "preview" email of any type, or e.g. via Feedback.  but it
seemed like the Configure Email Settings page should have a dedicated
way to test sending
This commit is contained in:
Lance Edgar 2023-05-19 17:16:19 -05:00
parent 05bb3849a2
commit de13e48aa5
2 changed files with 84 additions and 16 deletions

View file

@ -297,6 +297,22 @@ class EmailSettingView(MasterView):
'true' if data['hidden'] else 'false')
return {'ok': True}
def send_test(self):
"""
AJAX view for sending a test email.
"""
data = self.request.json_body
recip = data.get('recipient')
if not recip:
return {'error': "Must specify recipient"}
app = self.get_rattail_app()
app.send_email('hello', to=[recip], cc=None, bcc=None,
default_subject="Hello world")
return {'ok': True}
@classmethod
def defaults(cls, config):
cls._email_defaults(config)
@ -318,6 +334,16 @@ class EmailSettingView(MasterView):
permission='{}.configure'.format(permission_prefix),
renderer='json')
# send test
config.add_route('{}.send_test'.format(route_prefix),
'{}/send-test'.format(url_prefix),
request_method='POST')
config.add_view(cls, attr='send_test',
route_name='{}.send_test'.format(route_prefix),
permission='{}.configure'.format(permission_prefix),
renderer='json')
# TODO: deprecate / remove this
ProfilesView = EmailSettingView