Skip to content

Commit

Permalink
SendGrid: Set to field when using merge_data (#14)
Browse files Browse the repository at this point in the history
* Set to field when using merge_data

The `to` field is required even if providing recipient addresses in x-smtpapi. See https://sendgrid.com/docs/API_Reference/Web_API/mail.html#-send.

* Check data['to'] contains expected emails

* Add space for toname check

* Make `to` expected data contain email only
  • Loading branch information
lewistaylor authored and medmunds committed May 18, 2016
1 parent 23becd3 commit 72d8994
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions anymail/backends/sendgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def serialize_data(self):
self.set_recipients('to', self.to_list)
else:
# Merge-friendly smtpapi 'to' field
self.set_recipients('to', self.to_list)
self.smtpapi['to'] = [email.address for email in self.to_list]
self.all_recipients += self.to_list

Expand Down
4 changes: 2 additions & 2 deletions tests/test_sendgrid_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ def test_merge_data(self):

data = self.get_api_call_data()
smtpapi = self.get_smtpapi()
self.assertNotIn('to', data) # recipients should be moved to smtpapi-to with merge_data
self.assertNotIn('toname', data)
self.assertEqual(data['toname'], [' ', 'Bob'])
self.assertEqual(data['to'], ['alice@example.com', 'bob@example.com'])
self.assertEqual(smtpapi['to'], ['alice@example.com', 'Bob <bob@example.com>'])
self.assertEqual(smtpapi['sub'], {
':name': ["Alice", "Bob"],
Expand Down

0 comments on commit 72d8994

Please sign in to comment.