Skip to content
Snippets Groups Projects
Unverified Commit c72eec46 authored by Olivier Dony's avatar Olivier Dony
Browse files

[FIX] mail: do not shadow SMTP errors with QUIT

When an exception is raised during the course of a normal SMTP session,
smtplib's `sendmail()` method will close the channel automatically,
so any further attempt at sending SMTP commands will fail with an
SMTPServerDisconnected error, even just calling `smtp.quit()`.
This will shadow the original error, and make debugging harder.

Fixes #1493
parent 6ef27bb9
No related branches found
No related tags found
No related merge requests found
......@@ -447,15 +447,13 @@ class IrMailServer(models.Model):
try:
message_id = message['Message-Id']
smtp = smtp_session
try:
smtp = smtp or self.connect(
smtp_server, smtp_port, smtp_user, smtp_password,
smtp_encryption, smtp_debug, mail_server_id=mail_server_id)
smtp.sendmail(smtp_from, smtp_to_list, message.as_string())
finally:
# do not quit() a pre-established smtp_session
if smtp is not None and not smtp_session:
smtp.quit()
smtp = smtp or self.connect(
smtp_server, smtp_port, smtp_user, smtp_password,
smtp_encryption, smtp_debug, mail_server_id=mail_server_id)
smtp.sendmail(smtp_from, smtp_to_list, message.as_string())
# do not quit() a pre-established smtp_session
if not smtp_session:
smtp.quit()
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment