#27210 closed Bug (fixed)
smtp EmailBackend doesn't honor fail_silently=True when receiving a socket level connection error
Reported by: | Tom Hendrikx | Owned by: | Vesteinn Snaebjarnarson |
---|---|---|---|
Component: | Core (Mail) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
The Python SMTPlib does not wrap connection errors that occur on socket level while setting up a connection. That means that Django needs to catch socket errors too (@here: https://github.com/django/django/blob/master/django/core/mail/backends/smtp.py#L73) when fail_silently
is enabled and the connection fails with a socket.error
(f.i.: Connection refused) or socket.timeout
(f.i. Connection timed out).
I tested this by setting up a django 1.10 with following settings:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'localhost' EMAIL_PORT = 10587 # nothing is listening here!
Then I copied the core admincommand sendtestemail.py
to one of my apps, and modified https://github.com/django/django/blob/master/django/core/management/commands/sendtestemail.py#L34 to set fail_silently=True
. This should yield no error, but it ends in a Traceback.
Original problem of this issue for me was the utils.log.AdminEmailHandler
that uses this feature. I can try to create some test cases for this issue when the issue is deemed valid.
Change History (7)
comment:1 by , 8 years ago
Summary: | SMTPBackend does not honor fail_silently=True when receiving a socket level connection error → logging EmailBackend does not honor fail_silently=True when receiving a socket level connection error |
---|
comment:2 by , 8 years ago
Summary: | logging EmailBackend does not honor fail_silently=True when receiving a socket level connection error → smtp EmailBackend doesn't honor fail_silently=True when receiving a socket level connection error |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 8 years ago
Patch needs improvement: | set |
---|
Please uncheck "Patch needs improvement" when review comments are addressed and tests are passing.
See pull request at https://github.com/django/django/pull/7282
Added ConnectionError to the exception tuple for the SMTPBackend with tests.