Skip to content

Commit

Permalink
smtplib: catch OSError, not SMTPException
Browse files Browse the repository at this point in the history
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
  • Loading branch information
evan-goode authored and m-blaha committed Oct 7, 2024
1 parent ca4c522 commit 4d7aeb6
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 4d7aeb6

Please sign in to comment.