Skip to content

Commit 4f34935

Browse files
committed
Docs: document AMPHTML
* Add general instructions for sending AMP Email with Django * Document ability of Amazon SES and SendGrid backends to send AMPHTML (via arbitrary alternative parts) * Add AMP Email row to ESP support table
1 parent d1ef61d commit 4f34935

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Other
5050

5151
* Test against Django 3.2 prerelease (including support for Python 3.9)
5252

53+
* Document how to send AMP for Email with Django, and note which ESPs support it.
54+
5355
* Move CI testing to GitHub Actions (and stop using Travis-CI).
5456

5557
* Internal: catch invalid recipient status earlier in ESP response parsing

docs/esps/amazon_ses.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ Limitations and quirks
9393
Amazon SES is one of the few ESPs that *does* support sending arbitrary alternative
9494
message parts (beyond just a single text/plain and text/html part).
9595

96+
**AMP for Email**
97+
Amazon SES supports sending AMPHTML email content. To include it, use
98+
``message.attach_alternative("...AMPHTML content...", "text/x-amp-html")``
99+
(and be sure to also include regular HTML and text bodies, too).
100+
96101
**Spoofed To header and multiple From emails allowed**
97102
Amazon SES is one of the few ESPs that supports spoofing the :mailheader:`To` header
98103
(see :ref:`message-headers`) and supplying multiple addresses in a message's `from_email`.
@@ -252,7 +257,7 @@ message attributes.
252257
Amazon's templated email APIs don't support several features available for regular email.
253258
When :attr:`~anymail.message.AnymailMessage.template_id` is used:
254259

255-
* Attachments are not supported
260+
* Attachments and alternative parts (including AMPHTML) are not supported
256261
* Extra headers are not supported
257262
* Overriding the template's subject or body is not supported
258263
* Anymail's :attr:`~anymail.message.AnymailMessage.metadata` is not supported

docs/esps/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Email Service Provider |Amazon SES| |Mailgun| |Mailje
4343
:attr:`~AnymailMessage.tags` Yes Yes Max 1 tag Yes Max 1 tag Yes Yes Max 1 tag
4444
:attr:`~AnymailMessage.track_clicks` No Yes Yes Yes Yes Yes No Yes
4545
:attr:`~AnymailMessage.track_opens` No Yes Yes Yes Yes Yes No Yes
46+
:ref:`amp-email` Yes Yes No No No Yes No Yes
4647

4748
.. rubric:: :ref:`templates-and-merge`
4849
---------------------------------------------------------------------------------------------------------------------------------------------------

docs/esps/sendgrid.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ Limitations and quirks
237237

238238
(Noted June, 2019 and December, 2019)
239239

240+
**Arbitrary alternative parts allowed**
241+
SendGrid is one of the few ESPs that *does* support sending arbitrary alternative
242+
message parts (beyond just a single text/plain and text/html part).
243+
244+
**AMP for Email**
245+
SendGrid supports sending AMPHTML email content. To include it, use
246+
``message.attach_alternative("...AMPHTML content...", "text/x-amp-html")``
247+
(and be sure to also include regular HTML and text bodies, too).
248+
240249
**No envelope sender overrides**
241250
SendGrid does not support overriding :attr:`~anymail.message.AnymailMessage.envelope_sender`
242251
on individual messages.

docs/sending/django_email.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,34 @@ It's good practice to send equivalent content in your plain-text body
5858
and the html version.
5959

6060

61+
.. _amp-email:
62+
63+
.. rubric:: AMP Email
64+
65+
Django's :class:`~django.core.mail.EmailMultiAlternatives` also supports sending
66+
`AMP for email`_ content. Attach the AMP alternative with the MIME type
67+
:mimetype:`text/x-amp-html`. Add the AMPHTML first, before the regular html alternative,
68+
to keep the parts in the recommended order:
69+
70+
.. code-block:: python
71+
:emphasize-lines: 5-6
72+
73+
from django.core.mail import EmailMultiAlternatives
74+
75+
msg = EmailMultiAlternatives("Subject", "text body",
76+
77+
msg.attach_alternative("<!doctype html><html amp4email data-css-strict>...",
78+
"text/x-amp-html")
79+
msg.attach_alternative("<!doctype html><html>...", "text/html")
80+
msg.send()
81+
82+
Not all ESPs allow AMPHTML (check the chart under :ref:`supported-esps`).
83+
If yours doesn't, trying to send AMP content will raise an
84+
:ref:`unsupported feature <unsupported-features>` error.
85+
86+
.. _AMP for Email: https://amp.dev/about/email/
87+
88+
6189
.. _sending-attachments:
6290

6391
Attachments

0 commit comments

Comments
 (0)