Navigation Menu

Skip to content

Commit

Permalink
Added support for multiple recipients and cc - changed django backend…
Browse files Browse the repository at this point in the history
… to use message.to instead of message.recipients to remove risk of accidental exposure of BCC addresses
  • Loading branch information
frozenskys committed Mar 10, 2010
1 parent d667c31 commit af4d686
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
22 changes: 19 additions & 3 deletions src/postmark/core.py
@@ -1,4 +1,4 @@
__version__ = '0.1.4'
__version__ = '0.1.5'
__author__ = "David Martorana (http://davemartorana.com)"
__date__ = '2010-January-01'
__url__ = 'http://postmarkapp.com'
Expand Down Expand Up @@ -35,6 +35,8 @@ def __init__(self, **kwargs):
"name@email.com" or "First Last <name@email.com>" format
recipient: Who to send the email to, in either
"name@email.com" or "First Last <name@email.com>" format
cc: Who to copy the email to, in either
"name@email.com" or "First Last <name@email.com>" format
subject: Subject of the email
html_body: Email message in HTML
text_body: Email message in plain text
Expand All @@ -45,6 +47,7 @@ def __init__(self, **kwargs):
self.__sender = None
self.__reply_to = None
self.__recipient = None
self.__cc = None
self.__subject = None
self.__html_body = None
self.__text_body = None
Expand All @@ -55,7 +58,8 @@ def __init__(self, **kwargs):
'api_key',
'sender',
'reply_to',
'recipient',
'recipient',
'cc',
'subject',
'html_body',
'text_body',
Expand Down Expand Up @@ -133,10 +137,19 @@ def _set_custom_headers(self, value):
lambda self, value: setattr(self, '_PMMail__recipient', value),
lambda self: setattr(self, '_PMMail__recipient', None),
'''
The recipient, in either "name@email.com" or "First Last <name@email.com>" formats
The recipients, in either "name@email.com" or "First Last <name@email.com>" formats
'''
)

cc = property(
lambda self: self.__cc,
lambda self, value: setattr(self, '_PMMail__cc', value),
lambda self: setattr(self, '_PMMail__cc', None),
'''
The cc recipients, in either "name@email.com" or "First Last <name@email.com>" formats
'''
)

subject = property(
lambda self: self.__subject,
lambda self, value: setattr(self, '_PMMail__subject', value),
Expand Down Expand Up @@ -217,6 +230,9 @@ def send(self, test=False):
if self.__reply_to:
json_message['ReplyTo'] = self.__reply_to

if self.__cc:
json_message['Cc'] = self.__cc

if self.__html_body:
json_message['HtmlBody'] = self.__html_body

Expand Down
38 changes: 19 additions & 19 deletions src/postmark/django_backend.py
Expand Up @@ -36,26 +36,26 @@ def _send(self, message):
if not message.recipients():
return False
try:
for recipient in message.recipients():
if message.__class__.__name__ == 'EmailMultiAlternatives':
for alt in message.alternatives:
if alt[1] == "text/html":
html_body=alt[0]
break
postmark_message = PMMail(api_key=self.api_key,
subject=message.subject,
sender=message.from_email,
recipient=recipient,
text_body=message.body,
html_body=html_body)
recipients = ''.join(message.to)
if message.__class__.__name__ == 'EmailMultiAlternatives':
for alt in message.alternatives:
if alt[1] == "text/html":
html_body=alt[0]
break
postmark_message = PMMail(api_key=self.api_key,
subject=message.subject,
sender=message.from_email,
recipient=recipients,
text_body=message.body,
html_body=html_body)

else:
postmark_message = PMMail(api_key=self.api_key,
subject=message.subject,
sender=message.from_email,
recipient=recipient,
text_body=message.body)
postmark_message.send()
else:
postmark_message = PMMail(api_key=self.api_key,
subject=message.subject,
sender=message.from_email,
recipient=recipients,
text_body=message.body)
postmark_message.send()
except:
if self.fail_silently:
return False
Expand Down

0 comments on commit af4d686

Please sign in to comment.