From fb2a0136ab7ab7e5d505faed117a5f67f7caa51a Mon Sep 17 00:00:00 2001 From: Ross Patterson Date: Tue, 20 Mar 2012 10:28:43 -0700 Subject: [PATCH] Restore cc/bcc only support and add test from Chris: https://github.com/Pylons/pyramid_mailer/issues/14#issuecomment-4600509 --- pyramid_mailer/message.py | 4 ---- pyramid_mailer/tests.py | 25 +++++++++++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/pyramid_mailer/message.py b/pyramid_mailer/message.py index 3f97432..d1fb902 100644 --- a/pyramid_mailer/message.py +++ b/pyramid_mailer/message.py @@ -139,10 +139,6 @@ def validate(self): if not (self.recipients or self.cc or self.bcc): raise InvalidMessage("No recipients have been added") - if (self.cc or self.bcc) and not self.recipients: - raise InvalidMessage("Must have at least one direct recipient " - "even if cc or bcc set") - if not self.body and not self.html: raise InvalidMessage("No body has been set") diff --git a/pyramid_mailer/tests.py b/pyramid_mailer/tests.py index a148a1d..2c56241 100644 --- a/pyramid_mailer/tests.py +++ b/pyramid_mailer/tests.py @@ -168,8 +168,22 @@ def test_cc_without_recipients(self): body="testing", cc=["tosomeoneelse@example.com"]) mailer = Mailer() - from pyramid_mailer.exceptions import InvalidMessage - self.assertRaises(InvalidMessage, mailer.send, msg) + msgid = mailer.send(msg) + response = msg.get_response() + + self.assertTrue("Cc: tosomeoneelse@example.com" in str(response)) + self.assertTrue(msgid) + + def test_cc_without_recipients_2(self): + + from pyramid_mailer.message import Message + + msg = Message(subject="testing", + sender="sender@example.com", + body="testing", + cc=["tosomeoneelse@example.com"]) + response = msg.get_response() + self.assertTrue("Cc: tosomeoneelse@example.com" in str(response)) def test_bcc_without_recipients(self): @@ -181,8 +195,11 @@ def test_bcc_without_recipients(self): body="testing", bcc=["tosomeoneelse@example.com"]) mailer = Mailer() - from pyramid_mailer.exceptions import InvalidMessage - self.assertRaises(InvalidMessage, mailer.send, msg) + msgid = mailer.send(msg) + response = msg.get_response() + + self.assertFalse("Bcc: tosomeoneelse@example.com" in str(response)) + self.assertTrue(msgid) def test_attach(self):