Skip to content
Browse files

Fixed issue #50 - save changes made to email by sending backend

  • Loading branch information...
1 parent 28a317e commit 93c378e928feef8cf86d1794b0503611ee9dc739 @spookylukey committed Oct 22, 2015
Showing with 15 additions and 0 deletions.
  1. +1 −0 mailer/engine.py
  2. +14 −0 mailer/tests.py
View
1 mailer/engine.py
@@ -128,6 +128,7 @@ def send_all():
if email is not None:
email.connection = connection
email.send()
+ message.email = email # For the sake of MessageLog
MessageLog.objects.log(message, RESULT_SUCCESS)
sent += 1
else:
View
14 mailer/tests.py
@@ -28,6 +28,8 @@ def close(self):
pass
def send_messages(self, email_messages):
+ for m in email_messages:
+ m.extra_headers['X-Sent-By'] = 'django-mailer-tests'
self.outbox.extend(email_messages)
@@ -279,6 +281,18 @@ def test_throttling_delivery(self):
# Notes: 2 * TIME because 2 emails are sent during the test
self.assertGreater(throttled_time, 2 * TIME)
+ def test_save_changes_to_email(self):
+ """
+ Test that changes made to the email by the backend are
+ saved in MessageLog.
+ """
+ with self.settings(MAILER_EMAIL_BACKEND="mailer.tests.TestMailerEmailBackend"):
+ mailer.send_mail("Subject", "Body", "sender@example.com", ["recipient@example.com"])
+ engine.send_all()
+ m = MessageLog.objects.get()
+ self.assertEqual(m.email.extra_headers['X-Sent-By'],
+ 'django-mailer-tests')
+
class TestLockNormal(TestCase):
def setUp(self):

0 comments on commit 93c378e

Please sign in to comment.
Something went wrong with that request. Please try again.