From 71c78f93fb78c86576c7ca243058ef5fc5f2c0ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 1 Dec 2023 09:54:40 +0100 Subject: [PATCH] Retry to send email when server unexpectedly disconnect Closes #12790 (grafted from fc0afccf55b95644352655d8c081713df77d1662) --HG-- branch : 7.0 --- trytond/trytond/sendmail.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/trytond/trytond/sendmail.py b/trytond/trytond/sendmail.py index 883c5f48d5..43c66456af 100644 --- a/trytond/trytond/sendmail.py +++ b/trytond/trytond/sendmail.py @@ -45,6 +45,14 @@ def sendmail(from_addr, to_addrs, msg, server=None, strict=False): time.sleep(0.02 * (retry - count)) try: senderrs = server.sendmail(from_addr, to_addrs, msg.as_string()) + except smtplib.SMTPServerDisconnected: + if count: + server = get_smtp_server(strict=strict) + if server: + continue + if strict: + raise + logger.error('fail to send email', exc_info=True) except smtplib.SMTPResponseException as e: if count and 400 <= e.smtp_code <= 499 and hasattr(server, 'uri'): server.quit()