Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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 Tom Hendrikx, 8 years ago

Summary: SMTPBackend does not honor fail_silently=True when receiving a socket level connection errorlogging EmailBackend does not honor fail_silently=True when receiving a socket level connection error

comment:2 by Tim Graham, 8 years ago

Summary: logging EmailBackend does not honor fail_silently=True when receiving a socket level connection errorsmtp EmailBackend doesn't honor fail_silently=True when receiving a socket level connection error
Triage Stage: UnreviewedAccepted

comment:3 by Vesteinn Snaebjarnarson, 8 years ago

Owner: changed from nobody to Vesteinn Snaebjarnarson
Status: newassigned

comment:4 by Vesteinn Snaebjarnarson, 8 years ago

Has patch: set

See pull request at https://github.com/django/django/pull/7282

Added ConnectionError to the exception tuple for the SMTPBackend with tests.

Last edited 8 years ago by Tim Graham (previous) (diff)

comment:5 by Tim Graham, 8 years ago

Patch needs improvement: set

Please uncheck "Patch needs improvement" when review comments are addressed and tests are passing.

comment:6 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In 602bffe7:

Fixed #27210 -- Allowed SMTPBackend to fail silently on a socket connection error.

comment:7 by GitHub <noreply@…>, 8 years ago

In f6fe8ecc:

Refs #27210 -- Fixed isolation of test_fail_silently_on_connection_error.

The test wouldn't pass if a mail server is running on the system.

Note: See TracTickets for help on using tickets.
Back to Top