mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
Keep angle brackets on SendGrid smtp-id
SendGrid seems to consistently use <angle brackets> on Message-ID and smtp-id.
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
from email.utils import unquote
|
|
||||||
|
|
||||||
from django.core.mail import make_msgid
|
from django.core.mail import make_msgid
|
||||||
from requests.structures import CaseInsensitiveDict
|
from requests.structures import CaseInsensitiveDict
|
||||||
|
|
||||||
@@ -115,8 +113,7 @@ class SendGridPayload(RequestsPayload):
|
|||||||
# Workaround for missing message ID (smtp-id) in SendGrid engagement events
|
# Workaround for missing message ID (smtp-id) in SendGrid engagement events
|
||||||
# (click and open tracking): because unique_args get merged into the raw event
|
# (click and open tracking): because unique_args get merged into the raw event
|
||||||
# record, we can supply the 'smtp-id' field for any events missing it.
|
# record, we can supply the 'smtp-id' field for any events missing it.
|
||||||
# Must use the unquoted (no <angle brackets>) version to match other SendGrid APIs.
|
self.smtpapi.setdefault('unique_args', {})['smtp-id'] = self.message_id
|
||||||
self.smtpapi.setdefault('unique_args', {})['smtp-id'] = unquote(self.message_id)
|
|
||||||
|
|
||||||
def make_message_id(self):
|
def make_message_id(self):
|
||||||
"""Returns a Message-ID that could be used for this payload
|
"""Returns a Message-ID that could be used for this payload
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ class SendGridBackendStandardEmailTests(SendGridBackendMockAPITestCase):
|
|||||||
# make sure backend assigned a Message-ID for event tracking
|
# make sure backend assigned a Message-ID for event tracking
|
||||||
email_headers = json.loads(data['headers'])
|
email_headers = json.loads(data['headers'])
|
||||||
self.assertRegex(email_headers['Message-ID'], r'\<.+@sender\.example\.com\>') # id uses from_email's domain
|
self.assertRegex(email_headers['Message-ID'], r'\<.+@sender\.example\.com\>') # id uses from_email's domain
|
||||||
# make sure we added the unquoted Message-ID to unique_args for event notification
|
# make sure we added the Message-ID to unique_args for event notification
|
||||||
smtpapi = self.get_smtpapi()
|
smtpapi = self.get_smtpapi()
|
||||||
self.assertEqual(email_headers['Message-ID'], '<{}>'.format(smtpapi['unique_args']['smtp-id']))
|
self.assertEqual(email_headers['Message-ID'], smtpapi['unique_args']['smtp-id'])
|
||||||
|
|
||||||
@override_settings(ANYMAIL={'SENDGRID_USERNAME': 'sg_username', 'SENDGRID_PASSWORD': 'sg_password'})
|
@override_settings(ANYMAIL={'SENDGRID_USERNAME': 'sg_username', 'SENDGRID_PASSWORD': 'sg_password'})
|
||||||
def test_user_pass_auth(self):
|
def test_user_pass_auth(self):
|
||||||
@@ -110,7 +110,7 @@ class SendGridBackendStandardEmailTests(SendGridBackendMockAPITestCase):
|
|||||||
cc=['cc1@example.com', 'Also CC <cc2@example.com>'],
|
cc=['cc1@example.com', 'Also CC <cc2@example.com>'],
|
||||||
headers={'Reply-To': 'another@example.com',
|
headers={'Reply-To': 'another@example.com',
|
||||||
'X-MyHeader': 'my value',
|
'X-MyHeader': 'my value',
|
||||||
'Message-ID': 'mycustommsgid@sales.example.com'}) # should override backend msgid
|
'Message-ID': '<mycustommsgid@sales.example.com>'}) # should override backend msgid
|
||||||
email.send()
|
email.send()
|
||||||
data = self.get_api_call_data()
|
data = self.get_api_call_data()
|
||||||
self.assertEqual(data['subject'], "Subject")
|
self.assertEqual(data['subject'], "Subject")
|
||||||
@@ -123,13 +123,13 @@ class SendGridBackendStandardEmailTests(SendGridBackendMockAPITestCase):
|
|||||||
self.assertEqual(data['cc'], ['cc1@example.com', 'cc2@example.com'])
|
self.assertEqual(data['cc'], ['cc1@example.com', 'cc2@example.com'])
|
||||||
self.assertEqual(data['ccname'], [' ', 'Also CC'])
|
self.assertEqual(data['ccname'], [' ', 'Also CC'])
|
||||||
self.assertJSONEqual(data['headers'], {
|
self.assertJSONEqual(data['headers'], {
|
||||||
'Message-ID': 'mycustommsgid@sales.example.com',
|
'Message-ID': '<mycustommsgid@sales.example.com>',
|
||||||
'Reply-To': 'another@example.com',
|
'Reply-To': 'another@example.com',
|
||||||
'X-MyHeader': 'my value',
|
'X-MyHeader': 'my value',
|
||||||
})
|
})
|
||||||
# make sure custom Message-ID also added to unique_args
|
# make sure custom Message-ID also added to unique_args
|
||||||
self.assertJSONEqual(data['x-smtpapi'], {
|
self.assertJSONEqual(data['x-smtpapi'], {
|
||||||
'unique_args': {'smtp-id': 'mycustommsgid@sales.example.com'}
|
'unique_args': {'smtp-id': '<mycustommsgid@sales.example.com>'}
|
||||||
})
|
})
|
||||||
|
|
||||||
def test_html_message(self):
|
def test_html_message(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user