Skip to content

Commit

Permalink
Allow messages with cc or bcc but no recipients.
Browse files Browse the repository at this point in the history
Fixes #14.
  • Loading branch information
rpatterson committed Mar 15, 2012
1 parent 7a7f04b commit d2c6adf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyramid_mailer/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 32 additions & 0 deletions pyramid_mailer/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d2c6adf

Please sign in to comment.