Do MAILGUN_SENDER_DOMAIN and DEFAULT_FROM_EMAIL need matching domains when using Django AnyMail?

I’m working with Django AnyMail and MailGun for email delivery. Here’s my current configuration:

INSTALLED_APPS = [
    'django.contrib.admin',
    'anymail',
    'myapp',
]

ANYMAIL = {
    "MAILGUN_API_KEY": "<my-api-key>",
    "MAILGUN_SENDER_DOMAIN": 'mail.mysite.org',
}
EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend"
DEFAULT_FROM_EMAIL = "[email protected]"

I recently updated my setup so that MAILGUN_SENDER_DOMAIN and the domain part of DEFAULT_FROM_EMAIL are no longer identical. After this change, my email sending functionality stopped working completely. I suspect that MailGun requires both domains to match for successful email delivery, but I can’t find clear information about this requirement in the official docs. Has anyone encountered this issue before? Is domain matching actually mandatory for the integration to work properly?

yeah, ran into this same issue recently. mailgun’s strict about sender domains - you can’t send from any domain without verifying it first. check your mailgun control panel under sending > domains and make sure mysite.org is added, not just mail.mysite.org. that domain mismatch is def causing your failures.

MailGun doesn’t require domain matching, but you’re missing something important. When you set MAILGUN_SENDER_DOMAIN as ‘mail.mysite.org’, that exact subdomain needs verification in your MailGun dashboard. Sending from ‘[email protected]’ while only having ‘mail.mysite.org’ authorized? MailGun will reject those emails. I hit this same problem last year. Two fixes: add ‘mysite.org’ as an authorized domain in MailGun, or change DEFAULT_FROM_EMAIL to ‘[email protected]’. First option’s cleaner - recipients won’t see that extra subdomain. Check your MailGun logs for authentication failures to confirm this is what’s happening.

Domain verification is definitely your problem. MailGun whitelists every sending domain - you’ve got to explicitly authorize each one in your account settings. I learned this the hard way when I switched from single domain to multiple subdomains. MailGun treats each domain and subdomain as completely separate entities that need their own verification. Your MAILGUN_SENDER_DOMAIN tells AnyMail which verified domain to use for API calls, but if DEFAULT_FROM_EMAIL points to an unverified domain, the service just silently drops those messages. Go to your MailGun dashboard and add mysite.org as a verified domain alongside your existing mail.mysite.org entry. You’ll need to add DNS records for verification, so give it time to propagate before you test again.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.