pythondjangomailgundjango-anymail

With Django AnyMail with MailGun, does the MAILGUN_SENDER_DOMAIN have to match the domain in the DEFAULT_FROM_EMAIL?


Consider the following settings.py snippet from https://github.com/anymail/django-anymail:

INSTALLED_APPS = [
    # ...
    "anymail",
    # ...
]

ANYMAIL = {
    # (exact settings here depend on your ESP...)
    "MAILGUN_API_KEY": "<your Mailgun key>",
    "MAILGUN_SENDER_DOMAIN": 'mg.example.com',  # your Mailgun domain, if needed
}
EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend"  # or sendgrid.EmailBackend, or...
DEFAULT_FROM_EMAIL = "you@example.com"  # if you don't already have this in settings

In this example, both the MAILGUN_SENDER_DOMAIN and DEFAULT_FROM_EMAIL have the domain example.com.

We've recently made a change such that the two domains are different, and it seems that I am no longer able to send emails using the AnyMail backend. My theory is that MailGun 'enforces' the two domains to be the same, but it is not clear to me from the documentation whether this is indeed the case. Can anyone confirm whether this is required?


Solution

  • I figured out that the domains don't have to be the same. By looking at the logs in the MailGun console, I noticed that there was a 'Not delivering to previously bounced address' error:

    enter image description here

    I tried a different email address and it worked.