@@ -4,22 +4,20 @@ SparkPost
4
4
=========
5
5
6
6
Anymail integrates with the `SparkPost `_ email service, using their
7
- Python :pypi: ` sparkpost ` API client package .
7
+ ` Transmissions API`_ .
8
8
9
- .. _SparkPost : https://www.sparkpost.com/
10
-
11
-
12
- Installation
13
- ------------
9
+ .. versionchanged :: 8.0
14
10
15
- You must ensure the :pypi: `sparkpost ` package is installed to use Anymail's SparkPost
16
- backend. Either include the "sparkpost" option when you install Anymail:
11
+ Earlier Anymail versions used the official Python :pypi: `sparkpost ` API client.
12
+ That library is no longer maintained, and Anymail now calls SparkPost's HTTP API
13
+ directly. This change should not affect most users, but you should make sure you
14
+ provide :setting: `SPARKPOST_API_KEY <ANYMAIL_SPARKPOST_API_KEY> ` in your
15
+ Anymail settings (Anymail doesn't check environment variables), and if you are
16
+ using Anymail's :ref: `esp_extra <sparkpost-esp-extra >` you will need to update that
17
+ to use Transmissions API parameters.
17
18
18
- .. code-block :: console
19
-
20
- $ pip install "django-anymail[sparkpost]"
21
-
22
- or separately run `pip install sparkpost `.
19
+ .. _SparkPost : https://www.sparkpost.com/
20
+ .. _Transmissions API : https://developers.sparkpost.com/api/transmissions/
23
21
24
22
25
23
Settings
@@ -44,9 +42,6 @@ in your settings.py.
44
42
A SparkPost API key with at least the "Transmissions: Read/Write" permission.
45
43
(Manage API keys in your `SparkPost account API keys `_.)
46
44
47
- This setting is optional; if not provided, the SparkPost API client will attempt
48
- to read your API key from the `SPARKPOST_API_KEY ` environment variable.
49
-
50
45
.. code-block :: python
51
46
52
47
ANYMAIL = {
@@ -58,15 +53,21 @@ Anymail will also look for ``SPARKPOST_API_KEY`` at the
58
53
root of the settings file if neither ``ANYMAIL["SPARKPOST_API_KEY"] ``
59
54
nor ``ANYMAIL_SPARKPOST_API_KEY `` is set.
60
55
56
+ .. versionchanged :: 8.0
57
+
58
+ This setting is required. If you store your API key in an environment variable, load
59
+ it into your Anymail settings: ``"SPARKPOST_API_KEY": os.environ["SPARKPOST_API_KEY"] ``.
60
+ (Earlier Anymail releases used the SparkPost Python library, which would look for
61
+ the environment variable.)
62
+
61
63
.. _SparkPost account API keys : https://app.sparkpost.com/account/credentials
62
64
63
65
64
66
.. setting :: ANYMAIL_SPARKPOST_API_URL
65
67
66
68
.. rubric :: SPARKPOST_API_URL
67
69
68
- The `SparkPost API Endpoint `_ to use. This setting is optional; if not provided, Anymail will
69
- use the :pypi: `python-sparkpost ` client default endpoint (``"https://api.sparkpost.com/api/v1" ``).
70
+ The `SparkPost API Endpoint `_ to use. The default is ``"https://api.sparkpost.com/api/v1" ``.
70
71
71
72
Set this to use a SparkPost EU account, or to work with any other API endpoint including
72
73
SparkPost Enterprise API and SparkPost Labs.
@@ -79,8 +80,6 @@ SparkPost Enterprise API and SparkPost Labs.
79
80
}
80
81
81
82
You must specify the full, versioned API endpoint as shown above (not just the base_uri).
82
- This setting only affects Anymail's calls to SparkPost, and will not apply to other code
83
- using :pypi: `python-sparkpost `.
84
83
85
84
.. _SparkPost API Endpoint : https://developers.sparkpost.com/api/index.html#header-api-endpoints
86
85
@@ -90,28 +89,47 @@ using :pypi:`python-sparkpost`.
90
89
esp_extra support
91
90
-----------------
92
91
93
- To use SparkPost features not directly supported by Anymail, you can
94
- set a message's :attr: `~anymail.message.AnymailMessage.esp_extra ` to
95
- a ` dict ` of parameters for python-sparkpost's ` transmissions.send method `_.
96
- Any keys in your :attr: ` esp_extra ` dict will override Anymail's normal
97
- values for that parameter .
92
+ To use SparkPost features not directly supported by Anymail, you can set
93
+ a message's :attr: `~anymail.message.AnymailMessage.esp_extra ` to a ` dict `
94
+ of ` transmissions API request body `_ data. Anymail will deeply merge your overrides
95
+ into the normal API payload it has constructed, with esp_extra taking precedence
96
+ in conflicts .
98
97
99
- Example:
98
+ Example (you probably wouldn't combine all of these options at once) :
100
99
101
100
.. code-block :: python
102
101
103
102
message.esp_extra = {
104
- ' transactional' : True , # treat as transactional for unsubscribe and suppression
105
- ' description' : " Marketing test-run for new templates" ,
106
- ' use_draft_template' : True ,
103
+ " options" : {
104
+ # Treat as transactional for unsubscribe and suppression:
105
+ " transactional" : True ,
106
+ # Override your default dedicated IP pool:
107
+ " ip_pool" : " transactional_pool" ,
108
+ },
109
+ # Add a description:
110
+ " description" : " Test-run for new templates" ,
111
+ " content" : {
112
+ # Use draft rather than published template:
113
+ " use_draft_template" : True ,
114
+ # Use an A/B test:
115
+ " ab_test_id" : " highlight_support_links" ,
116
+ },
117
+ # Use a stored recipients list (overrides message to/cc/bcc):
118
+ " recipients" : {
119
+ " list_id" : " design_team"
120
+ },
107
121
}
108
122
123
+ Note that including ``"recipients" `` in esp_extra will *completely * override the
124
+ recipients list Anymail generates from your message's to/cc/bcc fields, along with any
125
+ per-recipient :attr: `~anymail.message.AnymailMessage.merge_data ` and
126
+ :attr: `~anymail.message.AnymailMessage.merge_metadata `.
109
127
110
128
(You can also set `"esp_extra" ` in Anymail's :ref: `global send defaults <send-defaults >`
111
129
to apply it to all messages.)
112
130
113
- .. _transmissions.send method :
114
- https://python- sparkpost.readthedocs.io/en/latest/ api/transmissions.html#sparkpost.transmissions.Transmissions.send
131
+ .. _transmissions API request body :
132
+ https://developers. sparkpost.com/ api/transmissions/#header-request-body
115
133
116
134
117
135
@@ -151,6 +169,13 @@ Limitations and quirks
151
169
(SparkPost's "recipient tags" are not available for tagging *messages *.
152
170
They're associated with individual *addresses * in stored recipient lists.)
153
171
172
+ **AMP for Email **
173
+ SparkPost supports sending AMPHTML email content. To include it, use
174
+ ``message.attach_alternative("...AMPHTML content...", "text/x-amp-html") ``
175
+ (and be sure to also include regular HTML and/or text bodies, too).
176
+
177
+ .. versionadded :: 8.0
178
+
154
179
**Envelope sender may use domain only **
155
180
Anymail's :attr: `~anymail.message.AnymailMessage.envelope_sender ` is used to
156
181
populate SparkPost's `'return_path' ` parameter. Anymail supplies the full
0 commit comments