Skip to content

Commit

Permalink
Mailgun (docs): Clarify API keys
Browse files Browse the repository at this point in the history
Explain account-level "Mailgun API keys"
vs. domain-level "sending API keys."
  • Loading branch information
medmunds committed Aug 25, 2023
1 parent de44b93 commit 6c5b6b7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ Release history
^^^^^^^^^^^^^^^
.. This extra heading level keeps the ToC from becoming unmanageably long
vNext
-----

*unreleased changes*

Other
~~~~~

* **Mailgun (docs):** Clarify account-level "Mailgun API keys" vs.
domain-level "sending API keys." (Thanks to `@sdarwin`_ for
reporting the issue.)


v10.1
-----

Expand Down Expand Up @@ -1562,6 +1575,7 @@ Features
.. _@puru02: https://github.com/puru02
.. _@RignonNoel: https://github.com/RignonNoel
.. _@sblondon: https://github.com/sblondon
.. _@sdarwin: https://github.com/sdarwin
.. _@sebashwa: https://github.com/sebashwa
.. _@sebbacon: https://github.com/sebbacon
.. _@slinkymanbyday: https://github.com/slinkymanbyday
Expand Down
36 changes: 33 additions & 3 deletions docs/esps/mailgun.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ in your settings.py.

.. rubric:: MAILGUN_API_KEY

Required for sending. Your Mailgun "Private API key" from the Mailgun
`API security settings`_:
Required for sending:

.. code-block:: python
Expand All @@ -44,6 +43,37 @@ Required for sending. Your Mailgun "Private API key" from the Mailgun
"MAILGUN_API_KEY": "<your API key>",
}
The key can be either:

* (recommended) a domain-level Mailgun "Sending API key," found in Mailgun's dashboard
under "Sending" > "Domain settings" > "Sending API keys" (make sure the correct
domain is selected in the popup at top right!)
* an account-level "Mailgun API key" from your Mailgun `API security settings`_.

The account-level API key permits sending from any verified domain,
but it also allows access to all other Mailgun APIs for your account
(which Anymail doesn't need).

The domain-level sending API key is preferred if you send from only
a single domain. With multiple domains, either use an account API key,
or supply the sending API key for a default domain in settings.py and
use Django's :func:`~django.core.mail.get_connection` to substitute
a different sending API key for other domains:

.. code-block:: python
from django.core.mail import EmailMessage, get_connection
# By default, use the settings.py MAILGUN_API_KEY:
message1 = EmailMessage(from_email="[email protected]", ...)
message1.send()
# Use a different sending API key for this message:
connection = get_connection(api_key=SENDING_API_KEY_FOR_OTHER_DOMAIN)
message2 = EmailMessage(from_email="[email protected]", ...,
connection=connection)
message2.send()
Anymail will also look for ``MAILGUN_API_KEY`` at the
root of the settings file if neither ``ANYMAIL["MAILGUN_API_KEY"]``
nor ``ANYMAIL_MAILGUN_API_KEY`` is set.
Expand Down Expand Up @@ -115,7 +145,7 @@ Email sender domain
-------------------

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

You will need to override this default if you are using
Expand Down

0 comments on commit 6c5b6b7

Please sign in to comment.