Retry to send email when server unexpectedly disconnect

Closes #12790
(grafted from fc0afccf55b95644352655d8c081713df77d1662)

--HG--
branch : 7.0
This commit is contained in:
Cédric Krier committed 2023-12-01 09:54:40 +01:00
1 parent 427c51902f
commit 71c78f93fb
1 file changed
+8
+8
View File
@@ -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()