Skip to content

Support for cc/bcc in Django backend #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 10, 2016
Merged

Support for cc/bcc in Django backend #83

merged 7 commits into from
Mar 10, 2016

Conversation

richleland
Copy link
Contributor

  • Refactored to use a custom message class that just preps data for the API (SparkPostMessage)
  • Added test utils file for the at_least_version function
  • Was able to really simplify the backend code - most of the logic lives in the message class now

formatted['bcc'] = message.bcc

if hasattr(message, 'reply_to') and message.reply_to:
formatted['reply_to'] = message.reply_to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django's EmailMessage wants a list for the reply_to field but we expect a string. A naive solution might be to concat the list with semicolons:

formatted['reply_to'] = ';'.join(message.reply_to)

Without this, using EmailMessage(reply_to=[...]) causes an API error:

SparkPostAPIException: Call to https://api.sparkpost.com/api/v1/transmissions returned 422, errors:

        invalid data format/type: field 'content.reply_to' is of type 'json_array', but needs to be of type 'string'

@ewandennis
Copy link
Contributor

Tested successfully on Django 1.9.4, python 2.7.11.
Test suite succeeded on python 2.7.11 and 3.5.1.

We no longer throw UnsupportedParam so people can remove except clauses. Worth noting in changelog?

We might want to include example code showing how to use CC etc with Django's EmailMessage? Something like this:

EmailMessage(
  subject='Hello from Django and python-sparkpost',
  body='Hello Django monsters!',
  from_email='django@sparkpostbox.com',
  to=['someone@somedomain.com'], 
  cc=['another@somedomain.com'],
  bcc=['athird@somedomain.com'],
  reply_to=['yetanother@somedomain.com']
).send()

@richleland
Copy link
Contributor Author

Thanks for the thorough review @ewandennis - can you take a look at the updates?

ewandennis added a commit that referenced this pull request Mar 10, 2016
Support for cc/bcc in Django backend
@ewandennis ewandennis merged commit 0aa08ed into master Mar 10, 2016
@ewandennis ewandennis deleted the ISSUE-75 branch March 10, 2016 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants