Permalink
Browse files

Allow messages with `cc` or `bcc` but no `recipients`.

  • Loading branch information...
rpatterson committed Mar 15, 2012
1 parent 7a7f04b commit d2c6adf5b9cee03df90b3fe1233ca769547fc634
Showing with 33 additions and 1 deletion.
  1. +1 −1 pyramid_mailer/message.py
  2. +32 −0 pyramid_mailer/tests.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:
View
@@ -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

0 comments on commit d2c6adf

Please sign in to comment.