@@ -24,6 +24,7 @@ def test_processed_event(self):
24242525 "timestamp" : 1461095246 ,
2626 "anymail_id" : "3c2f4df8-c6dd-4cd2-9b91-6582b81a0349" ,
27+ 2728 "sg_event_id" : "ZyjAM5rnQmuI1KFInHQ3Nw" ,
2829 "sg_message_id" : "wrfRRvF7Q0GgwUo2CvDmEA.filter0425p1mdw1.13037.57168B4A1D.0" ,
2930 "event" : "processed" ,
@@ -51,6 +52,7 @@ def test_delivered_event(self):
5152 raw_events = [{
5253 "ip" : "167.89.17.173" ,
5354 "response" : "250 2.0.0 OK 1461095248 m143si2210036ioe.159 - gsmtp " ,
55+ 5456 "sg_event_id" : "nOSv8m0eTQ-vxvwNwt3fZQ" ,
5557 "sg_message_id" : "wrfRRvF7Q0GgwUo2CvDmEA.filter0425p1mdw1.13037.57168B4A1D.0" ,
5658 "tls" : 1 ,
@@ -81,6 +83,7 @@ def test_dropped_invalid_event(self):
8183 "email" : "invalid@invalid" ,
8284 "anymail_id" : "c74002d9-7ccb-4f67-8b8c-766cec03c9a6" ,
8385 "timestamp" : 1461095250 ,
86+ 8487 "sg_event_id" : "3NPOePGOTkeM_U3fgWApfg" ,
8588 "sg_message_id" : "filter0093p1las1.9128.5717FB8127.0" ,
8689 "reason" : "Invalid" ,
@@ -106,6 +109,7 @@ def test_dropped_unsubscribed_event(self):
106109107110 "anymail_id" : "a36ec0f9-aabe-45c7-9a84-3e17afb5cb65" ,
108111 "timestamp" : 1461095250 ,
112+ 109113 "sg_event_id" : "oxy9OLwMTAy5EsuZn1qhIg" ,
110114 "sg_message_id" : "filter0199p1las1.4745.5717FB6F5.0" ,
111115 "reason" : "Unsubscribed Address" ,
@@ -130,6 +134,7 @@ def test_bounce_event(self):
130134 raw_events = [{
131135 "ip" : "167.89.17.173" ,
132136 "status" : "5.1.1" ,
137+ 133138 "sg_event_id" : "lC0Rc-FuQmKbnxCWxX1jRQ" ,
134139 "reason" : "550 5.1.1 The email account that you tried to reach does not exist." ,
135140 "sg_message_id" : "Lli-03HcQ5-JLybO9fXsJg.filter0077p1las1.21536.5717FC482.0" ,
@@ -157,6 +162,7 @@ def test_bounce_event(self):
157162 def test_deferred_event (self ):
158163 raw_events = [{
159164 "response" : "Email was deferred due to the following reason(s): [IPs were throttled by recipient server]" ,
165+ 160166 "sg_event_id" : "b_syL5UiTvWC_Ky5L6Bs5Q" ,
161167 "sg_message_id" : "u9Gvi3mzT6iC2poAb58_qQ.filter0465p1mdw1.8054.5718271B40.0" ,
162168 "event" : "deferred" ,
@@ -232,3 +238,29 @@ def test_click_event(self):
232238 self .
assertEqual (
event .
recipient ,
"[email protected] " )
233239 self .assertEqual (event .user_agent , "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36" )
234240 self .assertEqual (event .click_url , "http://www.example.com" )
241+
242+ def test_compatibility_message_id_from_smtp_id (self ):
243+ # Prior to v3.0, Anymail tried to use a custom Message-ID header as
244+ # the `message_id`, and relied on SendGrid passing that to webhooks as
245+ # 'smtp-id'. Make sure webhooks extract message_id for messages sent
246+ # with earlier Anymail versions. (See issue #108.)
247+ raw_events = [{
248+ "ip" : "167.89.17.173" ,
249+ "response" : "250 2.0.0 OK 1461095248 m143si2210036ioe.159 - gsmtp " ,
250+ 251+ "sg_event_id" : "nOSv8m0eTQ-vxvwNwt3fZQ" ,
252+ "sg_message_id" : "wrfRRvF7Q0GgwUo2CvDmEA.filter0425p1mdw1.13037.57168B4A1D.0" ,
253+ "tls" : 1 ,
254+ "event" : "delivered" ,
255+ 256+ "timestamp" : 1461095250 ,
257+ }]
258+ response = self .client .post ('/anymail/sendgrid/tracking/' ,
259+ content_type = 'application/json' , data = json .dumps (raw_events ))
260+ self .assertEqual (response .status_code , 200 )
261+ kwargs = self .assert_handler_called_once_with (self .tracking_handler , sender = SendGridTrackingWebhookView ,
262+ event = ANY , esp_name = 'SendGrid' )
263+ event = kwargs ['event' ]
264+ self .assertIsInstance (event , AnymailTrackingEvent )
265+ self .
assertEqual (
event .
message_id ,
"<[email protected] >" )
266+ self .assertEqual (event .metadata , {}) # smtp-id not left in metadata
0 commit comments