-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explain account-level "Mailgun API keys" vs. domain-level "sending API keys."
- Loading branch information
Showing
2 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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. | ||
|
@@ -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 | ||
|