[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 54a477d797 related to `fetchmail()`.
Possibly, a better way exists but it has to change some methods
signatures.

Closes #24877
opw-1851030
This commit is contained in:
Olivier-LAURENT
2018-06-06 10:33:30 +02:00
committed by Nicolas Martinelli
parent ea23a1ac8c
commit a52c545d12
+4 -2
View File
@@ -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