Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.5.x] Fixed #19382 -- Stopped smtp backend raising exception when a…

…lready closed

Thanks Sebastian Noack for the report and the initial patch.
Backport of ffa50ca from master.
  • Loading branch information...
commit 5b8c0d22cc07ca727c032edf3309fab9cb39f21d 1 parent 4081042
@claudep claudep authored
View
2  django/core/mail/backends/smtp.py
@@ -60,6 +60,8 @@ def open(self):
def close(self):
"""Closes the connection to the email server."""
+ if self.connection is None:
+ return
try:
try:
self.connection.quit()
View
10 tests/regressiontests/mail/tests.py
@@ -492,6 +492,16 @@ def test_recipient_without_domain(self):
self.assertEqual(message.get('from'), "tester")
self.assertEqual(message.get('to'), "django")
+ def test_close_connection(self):
+ """
+ Test that connection can be closed (even when not explicitely opened)
+ """
+ conn = mail.get_connection(username='', password='')
+ try:
+ conn.close()
+ except Exception as e:
+ self.fail("close() unexpectedly raised an exception: %s" % e)
+
class LocmemBackendTests(BaseEmailBackendTests, TestCase):
email_backend = 'django.core.mail.backends.locmem.EmailBackend'
Please sign in to comment.
Something went wrong with that request. Please try again.