Skip to content

Commit 36461e5

Browse files
committed
Keep angle brackets on SendGrid smtp-id
SendGrid seems to consistently use <angle brackets> on Message-ID and smtp-id.
1 parent df881fd commit 36461e5

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

anymail/backends/sendgrid.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from email.utils import unquote
2-
31
from django.core.mail import make_msgid
42
from requests.structures import CaseInsensitiveDict
53

@@ -115,8 +113,7 @@ def ensure_message_id(self):
115113
# Workaround for missing message ID (smtp-id) in SendGrid engagement events
116114
# (click and open tracking): because unique_args get merged into the raw event
117115
# record, we can supply the 'smtp-id' field for any events missing it.
118-
# Must use the unquoted (no <angle brackets>) version to match other SendGrid APIs.
119-
self.smtpapi.setdefault('unique_args', {})['smtp-id'] = unquote(self.message_id)
116+
self.smtpapi.setdefault('unique_args', {})['smtp-id'] = self.message_id
120117

121118
def make_message_id(self):
122119
"""Returns a Message-ID that could be used for this payload

tests/test_sendgrid_backend.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def test_send_mail(self):
6464
# make sure backend assigned a Message-ID for event tracking
6565
email_headers = json.loads(data['headers'])
6666
self.assertRegex(email_headers['Message-ID'], r'\<.+@sender\.example\.com\>') # id uses from_email's domain
67-
# make sure we added the unquoted Message-ID to unique_args for event notification
67+
# make sure we added the Message-ID to unique_args for event notification
6868
smtpapi = self.get_smtpapi()
69-
self.assertEqual(email_headers['Message-ID'], '<{}>'.format(smtpapi['unique_args']['smtp-id']))
69+
self.assertEqual(email_headers['Message-ID'], smtpapi['unique_args']['smtp-id'])
7070

7171
@override_settings(ANYMAIL={'SENDGRID_USERNAME': 'sg_username', 'SENDGRID_PASSWORD': 'sg_password'})
7272
def test_user_pass_auth(self):
@@ -110,7 +110,7 @@ def test_email_message(self):
110110
111111
headers={'Reply-To': '[email protected]',
112112
'X-MyHeader': 'my value',
113-
'Message-ID': '[email protected]'}) # should override backend msgid
113+
'Message-ID': '<[email protected]>'}) # should override backend msgid
114114
email.send()
115115
data = self.get_api_call_data()
116116
self.assertEqual(data['subject'], "Subject")
@@ -123,13 +123,13 @@ def test_email_message(self):
123123
self.assertEqual(data['cc'], ['[email protected]', '[email protected]'])
124124
self.assertEqual(data['ccname'], [' ', 'Also CC'])
125125
self.assertJSONEqual(data['headers'], {
126-
'Message-ID': '[email protected]',
126+
'Message-ID': '<[email protected]>',
127127
'Reply-To': '[email protected]',
128128
'X-MyHeader': 'my value',
129129
})
130130
# make sure custom Message-ID also added to unique_args
131131
self.assertJSONEqual(data['x-smtpapi'], {
132-
'unique_args': {'smtp-id': '[email protected]'}
132+
'unique_args': {'smtp-id': '<[email protected]>'}
133133
})
134134

135135
def test_html_message(self):

0 commit comments

Comments
 (0)