Log error when sending email fails. Wrap recipients in a list instead of putting the logic inside Mailer _build_message().

This commit is contained in:
leigh-mil 2020-02-06 11:40:09 -05:00
parent 0f69a48bbe
commit b2da9de040
3 changed files with 5 additions and 4 deletions

View File

@ -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()

View File

@ -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

View File

@ -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}
),