Skip to content

Commit

Permalink
Add support for passing in cc list
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich Leland committed Mar 2, 2016
1 parent 3cbcfe6 commit 3243823
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sparkpost/transmissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ def _translate_keys(self, **kwargs):
model['content']['html'] = kwargs.get('html')
model['content']['text'] = kwargs.get('text')
model['content']['template_id'] = kwargs.get('template')
model['content']['headers'] = kwargs.get('custom_headers')
model['content']['headers'] = kwargs.get('custom_headers', {})

recipient_list = kwargs.get('recipient_list')
if recipient_list:
model['recipients']['list_id'] = recipient_list
else:
recipients = kwargs.get('recipients', [])
cc = kwargs.get('cc')
if cc and len(recipients) > 0:
model['content']['headers']['CC'] = ','.join(cc)
formatted_ccs = self._extractRecipients(cc)
for recipient in formatted_ccs:
recipient['address'].update({'header_to': recipients[0]})
recipients = recipients + formatted_ccs
model['recipients'] = self._extractRecipients(recipients)

attachments = kwargs.get('attachments', [])
Expand Down
14 changes: 14 additions & 0 deletions test/test_transmissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ def test_translate_keys_for_email_parsing():
]


def test_translate_keys_with_cc():
t = Transmissions('uri', 'key')
results = t._translate_keys(recipients=['primary@example.com'],
cc=['ccone@example.com'])
assert results['recipients'] == [
{'address': {'email': 'primary@example.com'}},
{'address': {'email': 'ccone@example.com',
'header_to': 'primary@example.com'}},
]
assert results['content']['headers'] == {
'CC': 'ccone@example.com'
}


@responses.activate
def test_success_send():
responses.add(
Expand Down

0 comments on commit 3243823

Please sign in to comment.