Permalink
Browse files

Add some utility methods to PMBatchMail, make "send" in PMBatchMail c…

…all _check_values for each PMMail object before attempting to send
  • Loading branch information...
1 parent 8c7a5e6 commit 52bdfbc3718ce0317cf4756574c10252e9638117 @themartorana committed Jun 18, 2012
Showing with 26 additions and 1 deletion.
  1. +26 −1 postmark/core.py
View
@@ -308,7 +308,7 @@ def _check_values(self):
if not self.__api_key:
raise PMMailMissingValueException('Cannot send an e-mail without a Postmark API Key')
elif not self.__sender:
- raise PMMailMissingValueException('Cannot send an e-mail without a sender (.from field)')
+ raise PMMailMissingValueException('Cannot send an e-mail without a sender (.sender field)')
elif not self.__to:
raise PMMailMissingValueException('Cannot send an e-mail without at least one recipient (.to field)')
elif not self.__subject:
@@ -493,14 +493,39 @@ def __init__(self, **kwargs):
'''
)
+ def add_message(self, message):
+ '''
+ Add a message to the batch
+ '''
+ self.__messages.append(message)
+
+ def remove_message(self, message):
+ '''
+ Remove a message from the batch
+ '''
+ if message in self.__messages:
+ self.__messages.remove(message)
+
+ def _check_values(self):
+ '''
+ Make sure all values are of the appropriate
+ type and are not missing.
+ '''
+ for message in self.__messages:
+ message._check_values()
+
def send(self, test=None):
+ # Check messages for completeness prior to attempting to send
+ self._check_values()
+
# If test is not specified, attempt to read the Django setting
if test is None:
try:
from django.conf import settings as django_settings
test = getattr(django_settings, "POSTMARK_TEST_MODE", None)
except ImportError:
pass
+
# Split up into groups of 500 messages for sending
for messages in _chunks(self.messages, PMBatchMail.MAX_MESSAGES):
json_message = []

0 comments on commit 52bdfbc

Please sign in to comment.