File tree Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 3030
3131*Unreleased changes *
3232
33+ Features
34+ ~~~~~~~~
35+
36+ * **Mailgun: ** Add support for AMP for Email
37+ (via ``message.attach_alternative(..., "text/x-amp-html") ``).
38+
3339Fixes
3440~~~~~
3541
Original file line number Diff line number Diff line change @@ -310,6 +310,14 @@ def set_html_body(self, body):
310310 self .unsupported_feature ("multiple html parts" )
311311 self .data ["html" ] = body
312312
313+ def add_alternative (self , content , mimetype ):
314+ if mimetype .lower () == "text/x-amp-html" :
315+ if "amp-html" in self .data :
316+ self .unsupported_feature ("multiple html parts" )
317+ self .data ["amp-html" ] = content
318+ else :
319+ super ().add_alternative (content , mimetype )
320+
313321 def add_attachment (self , attachment ):
314322 # http://docs.python-requests.org/en/v2.4.3/user/advanced/#post-multiple-multipart-encoded-files
315323 if attachment .inline :
Original file line number Diff line number Diff line change @@ -237,6 +237,13 @@ Limitations and quirks
237237 Your tracking webhooks will receive metadata values (either that you provided or the
238238 default empty string) for *every * key used with *any * recipient in the send.
239239
240+ **AMP for Email **
241+ Mailgun supports sending AMPHTML email content. To include it, use
242+ ``message.attach_alternative("...AMPHTML content...", "text/x-amp-html") ``
243+ (and be sure to also include regular HTML and/or text bodies, too).
244+
245+ .. versionadded :: 8.2
246+
240247
241248.. _undocumented API requirement :
242249 https://mailgun.uservoice.com/forums/156243-feature-requests/suggestions/35668606
Original file line number Diff line number Diff line change @@ -301,6 +301,15 @@ def test_html_alternative(self):
301301 with self .assertRaises (AnymailUnsupportedFeature ):
302302 self .message .send ()
303303
304+ def test_amp_html_alternative (self ):
305+ # Mailgun *does* support text/x-amp-html alongside text/html
306+ self .message .attach_alternative ("<p>HTML</p>" , "text/html" )
307+ self .message .attach_alternative ("<p>And AMP HTML</p>" , "text/x-amp-html" )
308+ self .message .send ()
309+ data = self .get_api_call_data ()
310+ self .assertEqual (data ["html" ], "<p>HTML</p>" )
311+ self .assertEqual (data ["amp-html" ], "<p>And AMP HTML</p>" )
312+
304313 def test_alternatives_fail_silently (self ):
305314 # Make sure fail_silently is respected
306315 self .message .attach_alternative ("{'not': 'allowed'}" , "application/json" )
You can’t perform that action at this time.
0 commit comments