From a52c545d12039617432793f5ce8d8f4a4044b6c8 Mon Sep 17 00:00:00 2001 From: Olivier-LAURENT Date: Wed, 23 May 2018 15:56:36 +0200 Subject: [PATCH] [FIX] base: timeout on smtp connections Currently when connecting to a smtp server, if no response is returned and no error is raised, the `SMTP()` instantiation method never ends. This PR is inspired by 54a477d7971e8bff08b related to `fetchmail()`. Possibly, a better way exists but it has to change some methods signatures. Closes #24877 opw-1851030 --- openerp/addons/base/ir/ir_mail_server.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openerp/addons/base/ir/ir_mail_server.py b/openerp/addons/base/ir/ir_mail_server.py index b5fb772a851..50d96e9710d 100644 --- a/openerp/addons/base/ir/ir_mail_server.py +++ b/openerp/addons/base/ir/ir_mail_server.py @@ -28,6 +28,8 @@ from openerp.loglevels import ustr _logger = logging.getLogger(__name__) _test_logger = logging.getLogger('openerp.tests') +SMTP_TIMEOUT = 60 + class MailDeliveryException(except_orm): """Specific exception subclass for mail delivery errors""" @@ -215,9 +217,9 @@ class ir_mail_server(osv.osv): if not 'SMTP_SSL' in smtplib.__all__: raise UserError(_("Your OpenERP Server does not support SMTP-over-SSL. You could use STARTTLS instead." "If SSL is needed, an upgrade to Python 2.6 on the server-side should do the trick.")) - connection = smtplib.SMTP_SSL(host, port) + connection = smtplib.SMTP_SSL(host, port, timeout=SMTP_TIMEOUT) else: - connection = smtplib.SMTP(host, port) + connection = smtplib.SMTP(host, port, timeout=SMTP_TIMEOUT) connection.set_debuglevel(smtp_debug) if encryption == 'starttls': # starttls() will perform ehlo() if needed first