diff options
| author | Denis Stebunov <denis.stebunov@ivelum.com> | 2018-12-23 03:06:56 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-12-26 13:33:08 -0500 |
| commit | 277de2298465496b58808d22f67963544c76b16a (patch) | |
| tree | 676e1a2eb062f7d50aae3cc8063434773046c36a | |
| parent | 0b54ab0675a5443dbda2fc48e98ab474c295ac0c (diff) | |
Fixed #30058 -- Made SMTP EmailBackend.send_messages() return 0 for empty/error cases.
| -rw-r--r-- | django/core/mail/backends/smtp.py | 4 | ||||
| -rw-r--r-- | tests/mail/tests.py | 7 |
2 files changed, 8 insertions, 3 deletions
diff --git a/django/core/mail/backends/smtp.py b/django/core/mail/backends/smtp.py index d061fb5750..50b5b048ec 100644 --- a/django/core/mail/backends/smtp.py +++ b/django/core/mail/backends/smtp.py @@ -98,13 +98,13 @@ class EmailBackend(BaseEmailBackend): messages sent. """ if not email_messages: - return + return 0 with self._lock: new_conn_created = self.open() if not self.connection or new_conn_created is None: # We failed silently on open(). # Trying to send would be pointless. - return + return 0 num_sent = 0 for message in email_messages: sent = self._send(message) diff --git a/tests/mail/tests.py b/tests/mail/tests.py index ac44996ff9..f0f91e7b40 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -1527,7 +1527,12 @@ class SMTPBackendTests(BaseEmailBackendTests, SMTPBackendTestsBase): backend.connection = True backend.open = lambda: None email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com']) - self.assertEqual(backend.send_messages([email]), None) + self.assertEqual(backend.send_messages([email]), 0) + + def test_send_messages_empty_list(self): + backend = smtp.EmailBackend() + backend.connection = True + self.assertEqual(backend.send_messages([]), 0) def test_send_messages_zero_sent(self): """A message isn't sent if it doesn't have any recipients.""" |
