From d2c6adf5b9cee03df90b3fe1233ca769547fc634 Mon Sep 17 00:00:00 2001 From: Ross Patterson Date: Thu, 15 Mar 2012 13:54:39 -0700 Subject: [PATCH] Allow messages with `cc` or `bcc` but no `recipients`. Fixes Pylons/pyramid_mailer#14. --- pyramid_mailer/message.py | 2 +- pyramid_mailer/tests.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/pyramid_mailer/message.py b/pyramid_mailer/message.py index 3b0e6ae..6428856 100644 --- a/pyramid_mailer/message.py +++ b/pyramid_mailer/message.py @@ -136,7 +136,7 @@ def validate(self): Checks if message is valid and raises appropriate exception. """ - if not self.recipients: + if not (self.recipients or self.cc or self.bcc): raise InvalidMessage("No recipients have been added") if not self.body and not self.html: diff --git a/pyramid_mailer/tests.py b/pyramid_mailer/tests.py index 0f1dd23..7a3e1de 100644 --- a/pyramid_mailer/tests.py +++ b/pyramid_mailer/tests.py @@ -158,6 +158,38 @@ def test_cc(self): response = msg.get_response() self.assert_("Cc: tosomeoneelse@example.com" in str(response)) + def test_cc_without_recipients(self): + + from pyramid_mailer.message import Message + from pyramid_mailer.mailer import Mailer + + msg = Message(subject="testing", + sender="sender@example.com", + body="testing", + cc=["tosomeoneelse@example.com"]) + mailer = Mailer() + msgid = mailer.send(msg) + response = msg.get_response() + + self.assertTrue("Cc: tosomeoneelse@example.com" in str(response)) + self.assertTrue(msgid) + + def test_bcc_without_recipients(self): + + from pyramid_mailer.message import Message + from pyramid_mailer.mailer import Mailer + + msg = Message(subject="testing", + sender="sender@example.com", + body="testing", + bcc=["tosomeoneelse@example.com"]) + mailer = Mailer() + msgid = mailer.send(msg) + response = msg.get_response() + + self.assertFalse("Bcc: tosomeoneelse@example.com" in str(response)) + self.assertTrue(msgid) + def test_attach(self): from pyramid_mailer.message import Message