@@ -64,7 +64,7 @@ def __init__(self, **kwargs):
6464 bcc: Who to blind copy the email to, in either
65656666 Can be multiple values separated by commas (limit 20)
67- subject: Subject of the email. ***DO NOT SET if using Postmark templates
67+ subject: Subject of the email, ignored if using Postmark templates
6868 tag: Use for adding categorizations to your email
6969 html_body: Email message in HTML
7070 text_body: Email message in plain text
@@ -328,7 +328,7 @@ def _set_attachments(self, value):
328328 #####################
329329
330330
331- def _check_values (self , endpoint = 'email' ):
331+ def _check_values (self ):
332332 '''
333333 Make sure all values are of the appropriate
334334 type and are not missing.
@@ -339,13 +339,11 @@ def _check_values(self, endpoint='email'):
339339 raise PMMailMissingValueException ('Cannot send an e-mail without a sender (.sender field)' )
340340 elif not self .__to :
341341 raise PMMailMissingValueException ('Cannot send an e-mail without at least one recipient (.to field)' )
342- elif endpoint == 'email/withTemplate/' and ( not self .__template_id or not self .__template_model ):
342+ elif ( self . __template_id or self . __template_model ) and not all ([ self .__template_id , self .__template_model ] ):
343343 raise PMMailMissingValueException (
344344 'Cannot send a template e-mail without a both template_id and template_model set' )
345- elif not self .__subject and endpoint == 'email' :
345+ elif not any ([ self .__template_id , self . __template_model , self . __subject ]) :
346346 raise PMMailMissingValueException ('Cannot send an e-mail without a subject' )
347- elif self .__template_id and self .__subject :
348- raise PMMailMissingValueException ('If using Postmark templates, do not set the subject value' )
349347 elif not self .__html_body and not self .__text_body and not self .__template_id :
350348 raise PMMailMissingValueException ('Cannot send an e-mail without either an HTML or text version of your e-mail body' )
351349 if self .__track_opens and not self .__html_body :
@@ -429,16 +427,13 @@ def to_json_message(self):
429427
430428 return json_message
431429
432- def send (self , endpoint = 'email' , test = None ):
430+ def send (self , test = None ):
433431 '''
434432 Send the email through the Postmark system.
435433 Pass test=True to just print out the resulting
436434 JSON message being sent to Postmark
437-
438- endpoint: the name of the Postmark API endpoints
439-
440435 '''
441- self ._check_values (endpoint = endpoint )
436+ self ._check_values ()
442437
443438 # Set up message dictionary
444439 json_message = self .to_json_message ()
@@ -460,9 +455,14 @@ def send(self, endpoint='email', test=None):
460455 print ('JSON message is:\n %s' % json .dumps (json_message , cls = PMJSONEncoder ))
461456 return
462457
458+ if self .__template_id :
459+ endpoint_url = __POSTMARK_URL__ + 'email/withTemplate/'
460+ else :
461+ endpoint_url = __POSTMARK_URL__ + 'email'
462+
463463 # Set up the url Request
464464 req = Request (
465- __POSTMARK_URL__ + endpoint ,
465+ endpoint_url ,
466466 json .dumps (json_message , cls = PMJSONEncoder ).encode ('utf8' ),
467467 {
468468 'Accept' : 'application/json' ,
@@ -509,9 +509,6 @@ def send(self, endpoint='email', test=None):
509509 else :
510510 raise PMMailURLException ('URLError: The server couldn\' t fufill the request. (See "inner_exception" for details)' , err )
511511
512- def send_with_template (self , ** kwargs ):
513- self .send (endpoint = 'email/withTemplate/' , ** kwargs )
514-
515512
516513# Simple utility that returns a generator to chunk up a list into equal parts
517514def _chunks (l , n ):
0 commit comments