Skip to content

Commit

Permalink
smtplib: catch OSError, not SMTPException
Browse files Browse the repository at this point in the history
Upstream commit: aab7def

Some, but not all, types of connection error are caught by smtplib and
reraised as an smtplib.SMTPException. Notably, TimeoutError,
socket.gaierror (name resolution failure), and ConnectionRefusedError
and are not caught.

The more generic OSError should be caught here instead.

Resolves #1905
Resolves: https://issues.redhat.com/browse/RHEL-46030
  • Loading branch information
evan-goode authored and kontura committed Dec 13, 2024
1 parent 89c6f36 commit a1feaf8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion dnf/automatic/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def commit(self):
smtp = smtplib.SMTP(self._conf.email_host, timeout=300)
smtp.sendmail(email_from, email_to, message.as_string())
smtp.close()
except smtplib.SMTPException as exc:
except OSError as exc:
msg = _("Failed to send an email via '%s': %s") % (
self._conf.email_host, exc)
logger.error(msg)
Expand Down

0 comments on commit a1feaf8

Please sign in to comment.