From 394bbd189ba22e613b2fca5f5826dc27e4958ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 15 Oct 2018 22:52:52 +0200 Subject: [PATCH] Do not fail on SMTP connection error We just log the error and process the transaction. issue7775 review49631002 --- trytond/sendmail.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/trytond/sendmail.py b/trytond/sendmail.py index 0d56d044b9..c290a074ae 100644 --- a/trytond/sendmail.py +++ b/trytond/sendmail.py @@ -26,6 +26,8 @@ def sendmail_transactional( def sendmail(from_addr, to_addrs, msg, server=None): if server is None: server = get_smtp_server() + if not server: + return quit = True else: quit = False @@ -50,9 +52,14 @@ def get_smtp_server(uri=None): for key, value in parse_qs(uri.query, strict_parsing=True).items(): extra[key] = cast.get(key, lambda a: a)(value[0]) if uri.scheme.startswith('smtps'): - server = smtplib.SMTP_SSL(uri.hostname, uri.port, **extra) + connector = smtplib.SMTP_SSL else: - server = smtplib.SMTP(uri.hostname, uri.port, **extra) + connector = smtplib.SMTP + try: + server = connector(uri.hostname, uri.port, **extra) + except smtplib.SMTPConnectError: + logger.error('fail to connect to %s', uri) + return if 'tls' in uri.scheme: server.starttls()