summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addons/mail/models/mail_mail.py12
-rw-r--r--odoo/addons/base/models/ir_mail_server.py2
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