Skip to content

Commit 6c5b6b7

Browse files
committed
Mailgun (docs): Clarify API keys
Explain account-level "Mailgun API keys" vs. domain-level "sending API keys."
1 parent de44b93 commit 6c5b6b7

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

CHANGELOG.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ Release history
2525
^^^^^^^^^^^^^^^
2626
.. This extra heading level keeps the ToC from becoming unmanageably long
2727
28+
vNext
29+
-----
30+
31+
*unreleased changes*
32+
33+
Other
34+
~~~~~
35+
36+
* **Mailgun (docs):** Clarify account-level "Mailgun API keys" vs.
37+
domain-level "sending API keys." (Thanks to `@sdarwin`_ for
38+
reporting the issue.)
39+
40+
2841
v10.1
2942
-----
3043

@@ -1562,6 +1575,7 @@ Features
15621575
.. _@puru02: https://github.com/puru02
15631576
.. _@RignonNoel: https://github.com/RignonNoel
15641577
.. _@sblondon: https://github.com/sblondon
1578+
.. _@sdarwin: https://github.com/sdarwin
15651579
.. _@sebashwa: https://github.com/sebashwa
15661580
.. _@sebbacon: https://github.com/sebbacon
15671581
.. _@slinkymanbyday: https://github.com/slinkymanbyday

docs/esps/mailgun.rst

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ in your settings.py.
3434

3535
.. rubric:: MAILGUN_API_KEY
3636

37-
Required for sending. Your Mailgun "Private API key" from the Mailgun
38-
`API security settings`_:
37+
Required for sending:
3938

4039
.. code-block:: python
4140
@@ -44,6 +43,37 @@ Required for sending. Your Mailgun "Private API key" from the Mailgun
4443
"MAILGUN_API_KEY": "<your API key>",
4544
}
4645
46+
The key can be either:
47+
48+
* (recommended) a domain-level Mailgun "Sending API key," found in Mailgun's dashboard
49+
under "Sending" > "Domain settings" > "Sending API keys" (make sure the correct
50+
domain is selected in the popup at top right!)
51+
* an account-level "Mailgun API key" from your Mailgun `API security settings`_.
52+
53+
The account-level API key permits sending from any verified domain,
54+
but it also allows access to all other Mailgun APIs for your account
55+
(which Anymail doesn't need).
56+
57+
The domain-level sending API key is preferred if you send from only
58+
a single domain. With multiple domains, either use an account API key,
59+
or supply the sending API key for a default domain in settings.py and
60+
use Django's :func:`~django.core.mail.get_connection` to substitute
61+
a different sending API key for other domains:
62+
63+
.. code-block:: python
64+
65+
from django.core.mail import EmailMessage, get_connection
66+
# By default, use the settings.py MAILGUN_API_KEY:
67+
message1 = EmailMessage(from_email="support@default-domain.example.com", ...)
68+
message1.send()
69+
70+
# Use a different sending API key for this message:
71+
connection = get_connection(api_key=SENDING_API_KEY_FOR_OTHER_DOMAIN)
72+
message2 = EmailMessage(from_email="support@other-domain.example.com", ...,
73+
connection=connection)
74+
message2.send()
75+
76+
4777
Anymail will also look for ``MAILGUN_API_KEY`` at the
4878
root of the settings file if neither ``ANYMAIL["MAILGUN_API_KEY"]``
4979
nor ``ANYMAIL_MAILGUN_API_KEY`` is set.
@@ -115,7 +145,7 @@ Email sender domain
115145
-------------------
116146

117147
Mailgun's API requires identifying the sender domain.
118-
By default, Anymail uses the domain of each messages's `from_email`
148+
By default, Anymail uses the domain of each message's `from_email`
119149
(e.g., "example.com" for "from\@example.com").
120150

121151
You will need to override this default if you are using

0 commit comments

Comments
 (0)