From 24a392818b1bc0622338b576ee326b9c45773a15 Mon Sep 17 00:00:00 2001 From: Son Date: Mon, 27 Dec 2021 17:03:44 +0100 Subject: [PATCH] sl_sendmail tries by default 2 times before giving up: replace can_retry by retries --- app/email_utils.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/email_utils.py b/app/email_utils.py index 52f27ceb..4d713475 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -306,7 +306,7 @@ def send_email( TRANSACTIONAL_BOUNCE_EMAIL.format(transaction.id), to_email, msg, - can_retry=False, + retries=0, # no retry ) @@ -1269,7 +1269,7 @@ def sl_sendmail( mail_options=(), rcpt_options=(), is_forward: bool = False, - can_retry=True, + retries=2, ): """replace smtp.sendmail""" if NOT_SEND_EMAIL: @@ -1309,13 +1309,13 @@ def sl_sendmail( rcpt_options, ) except (SMTPServerDisconnected, SMTPRecipientsRefused) as e: - if can_retry: + if retries > 0: LOG.w( "SMTPServerDisconnected or SMTPRecipientsRefused error %s, retry", e, exc_info=True, ) - time.sleep(0.3) + time.sleep(0.3 * retries) sl_sendmail( from_addr, to_addr, @@ -1323,10 +1323,9 @@ def sl_sendmail( mail_options, rcpt_options, is_forward, - can_retry=False, + retries=retries - 1, ) else: - LOG.w("sendmail fails after retry") raise