Skip to content

Commit

Permalink
Fixed #19382 -- Stopped smtp backend raising exception when already c…
Browse files Browse the repository at this point in the history
…losed

Thanks Sebastian Noack for the report and the initial patch.
  • Loading branch information
claudep committed Jan 3, 2013
1 parent 1b3f832 commit ffa50ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions django/core/mail/backends/smtp.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def open(self):


def close(self): def close(self):
"""Closes the connection to the email server.""" """Closes the connection to the email server."""
if self.connection is None:
return
try: try:
try: try:
self.connection.quit() self.connection.quit()
Expand Down
10 changes: 10 additions & 0 deletions tests/regressiontests/mail/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -492,6 +492,16 @@ def test_recipient_without_domain(self):
self.assertEqual(message.get('from'), "tester") self.assertEqual(message.get('from'), "tester")
self.assertEqual(message.get('to'), "django") 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): class LocmemBackendTests(BaseEmailBackendTests, TestCase):
email_backend = 'django.core.mail.backends.locmem.EmailBackend' email_backend = 'django.core.mail.backends.locmem.EmailBackend'
Expand Down

0 comments on commit ffa50ca

Please sign in to comment.