diff options
| author | Olivier Dony <odo@odoo.com> | 2019-04-04 12:59:59 +0000 |
|---|---|---|
| committer | Nans Lefebvre <len@odoo.com> | 2019-04-05 14:10:41 +0000 |
| commit | 6fa292cec861da0ccfd3afe443062080171d2fc4 (patch) | |
| tree | c7a795fb0728853c52b52015be7cba262fa11fdb | |
| parent | 552da8dc8d55962c69dcdfec6fc4509f61cb27f1 (diff) | |
[FIX] ir_mail_server, mail: catch SMTPServerDisconnected exceptions
If the smtp session was dead, it would lead the whole mail batch to fail.
opw 1949270
closes odoo/odoo#32424
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
| -rw-r--r-- | addons/mail/models/mail_mail.py | 12 | ||||
| -rw-r--r-- | odoo/addons/base/models/ir_mail_server.py | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index f758456c77e..a2ba820656f 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -5,6 +5,7 @@ import base64 import datetime import logging import psycopg2 +import smtplib import threading import re @@ -394,11 +395,12 @@ class MailMail(models.Model): mail.id, mail.message_id) # mail status will stay on ongoing since transaction will be rollback raise - except psycopg2.Error: - # If an error with the database occurs, chances are that the cursor is unusable. - # This will lead to an `psycopg2.InternalError` being raised when trying to write - # `state`, shadowing the original exception and forbid a retry on concurrent - # update. Let's bubble it. + except (psycopg2.Error, smtplib.SMTPServerDisconnected): + # If an error with the database or SMTP session occurs, chances are that the cursor + # or SMTP session are unusable, causing further errors when trying to save the state. + _logger.exception( + 'Exception while processing mail with ID %r and Msg-Id %r.', + mail.id, mail.message_id) raise except Exception as e: failure_reason = tools.ustr(e) diff --git a/odoo/addons/base/models/ir_mail_server.py b/odoo/addons/base/models/ir_mail_server.py index 84b44c19aaf..285bc88822a 100644 --- a/odoo/addons/base/models/ir_mail_server.py +++ b/odoo/addons/base/models/ir_mail_server.py @@ -482,6 +482,8 @@ class IrMailServer(models.Model): # do not quit() a pre-established smtp_session if not smtp_session: smtp.quit() + except smtplib.SMTPServerDisconnected: + raise except Exception as e: params = (ustr(smtp_server), e.__class__.__name__, ustr(e)) msg = _("Mail delivery failed via SMTP server '%s'.\n%s: %s") % params |
