Skip to content

Commit

Permalink
Fixed #15750 -- Handle empty mail server credentials gracefully. Than…
Browse files Browse the repository at this point in the history
…ks, LeandroSouza and bedmondmark.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16494 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jezdez committed Jul 3, 2011
1 parent 1d270ac commit 3bd23ee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
10 changes: 8 additions & 2 deletions django/core/mail/backends/smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ def __init__(self, host=None, port=None, username=None, password=None,
super(EmailBackend, self).__init__(fail_silently=fail_silently)
self.host = host or settings.EMAIL_HOST
self.port = port or settings.EMAIL_PORT
self.username = username or settings.EMAIL_HOST_USER
self.password = password or settings.EMAIL_HOST_PASSWORD
if username is None:
self.username = settings.EMAIL_HOST_USER
else:
self.username = username
if password is None:
self.password = settings.EMAIL_HOST_PASSWORD
else:
self.password = password
if use_tls is None:
self.use_tls = settings.EMAIL_USE_TLS
else:
Expand Down
21 changes: 21 additions & 0 deletions tests/regressiontests/mail/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,24 @@ def flush_mailbox(self):

def get_mailbox_content(self):
return self.server.get_sink()

@override_settings(EMAIL_HOST_USER="not empty username",
EMAIL_HOST_PASSWORD="not empty password")
def test_email_authentication_use_settings(self):
backend = smtp.EmailBackend()
self.assertEqual(backend.username, 'not empty username')
self.assertEqual(backend.password, 'not empty password')

@override_settings(EMAIL_HOST_USER="not empty username",
EMAIL_HOST_PASSWORD="not empty password")
def test_email_authentication_override_settings(self):
backend = smtp.EmailBackend(username='username', password='password')
self.assertEqual(backend.username, 'username')
self.assertEqual(backend.password, 'password')

@override_settings(EMAIL_HOST_USER="not empty username",
EMAIL_HOST_PASSWORD="not empty password")
def test_email_disabled_authentication(self):
backend = smtp.EmailBackend(username='', password='')
self.assertEqual(backend.username, '')
self.assertEqual(backend.password, '')

0 comments on commit 3bd23ee

Please sign in to comment.