From b2da9de040d3fb2584a4e53b6df7f38d8b7ba68b Mon Sep 17 00:00:00 2001 From: leigh-mil Date: Thu, 6 Feb 2020 11:40:09 -0500 Subject: [PATCH] Log error when sending email fails. Wrap recipients in a list instead of putting the logic inside Mailer _build_message(). --- atst/jobs.py | 5 +++-- atst/utils/mailer.py | 2 +- tests/test_jobs.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/atst/jobs.py b/atst/jobs.py index 1ffe675f..6a12d423 100644 --- a/atst/jobs.py +++ b/atst/jobs.py @@ -210,7 +210,7 @@ def dispatch_create_atat_admin_user(self): @celery.task(bind=True) def dispatch_send_task_order_files(self): task_orders = TaskOrders.get_for_send_task_order_files() - recipients = app.config.get("MICROSOFT_TASK_ORDER_EMAIL_ADDRESS") + recipients = [app.config.get("MICROSOFT_TASK_ORDER_EMAIL_ADDRESS")] for task_order in task_orders: subject = translate( @@ -225,7 +225,8 @@ def dispatch_send_task_order_files(self): send_mail( recipients=recipients, subject=subject, body=body, attachments=[file] ) - except (AzureError, SMTPException): + except (AzureError, SMTPException) as err: + app.logger.exception(err) continue task_order.pdf_last_sent_at = pendulum.now() diff --git a/atst/utils/mailer.py b/atst/utils/mailer.py index 761e95da..a5dbfc0b 100644 --- a/atst/utils/mailer.py +++ b/atst/utils/mailer.py @@ -72,7 +72,7 @@ class Mailer(object): msg = EmailMessage() msg.set_content(body) msg["From"] = self.sender - msg["To"] = ", ".join(recipients) if type(recipients) == list else recipients + msg["To"] = ", ".join(recipients) msg["Subject"] = subject return msg diff --git a/tests/test_jobs.py b/tests/test_jobs.py index a0a92982..facea023 100644 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -324,7 +324,7 @@ def test_dispatch_send_task_order_files(monkeypatch, app): # Check that send_with_attachment was called with correct kwargs mock.assert_called_once_with( - recipients=app.config.get("MICROSOFT_TASK_ORDER_EMAIL_ADDRESS"), + recipients=[app.config.get("MICROSOFT_TASK_ORDER_EMAIL_ADDRESS")], subject=translate( "email.task_order_sent.subject", {"to_number": task_order.number} ),