diff --git a/django/core/mail/backends/smtp.py b/django/core/mail/backends/smtp.py
index b6f7f56..baffa8f 100644
a
|
b
|
class EmailBackend(BaseEmailBackend):
|
63 | 63 | try: |
64 | 64 | try: |
65 | 65 | self.connection.quit() |
66 | | except socket.sslerror: |
| 66 | except (socket.sslerror, smtplib.SMTPServerDisconnected): |
67 | 67 | # This happens when calling quit() on a TLS connection |
68 | | # sometimes. |
| 68 | # sometimes, or when the connection was already disconnected |
| 69 | # by the server. |
69 | 70 | self.connection.close() |
70 | 71 | except: |
71 | 72 | if self.fail_silently: |
diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
index a8fbf20..061c3f5 100644
a
|
b
|
class SMTPBackendTests(BaseEmailBackendTests, TestCase):
|
678 | 678 | |
679 | 679 | @classmethod |
680 | 680 | def tearDownClass(cls): |
| 681 | # for Ticket #19134 |
| 682 | backend = smtp.EmailBackend() |
| 683 | backend.username = None |
| 684 | backend.open() |
681 | 685 | cls._settings_override.disable() |
682 | 686 | cls.server.stop() |
| 687 | backend.close() |
683 | 688 | |
684 | 689 | def setUp(self): |
685 | 690 | super(SMTPBackendTests, self).setUp() |