Mailgun Domain not found: abc.com

12,730

Solution 1

Update 8/22/16: Anymail has been updated to take a new MAILGUN_SENDER_DOMAIN in settings.py. See version .5+ docs.

-- Original Answer You did not post your code for how you're sending your email, but you are probably trying to send using the simple send_mail() function:

from django.core.mail import send_mail

send_mail("Subject", "text body", "[email protected]",
          ["[email protected]"],)

When you use this method, Anymail pulls the domain out of your From address and tries to use this with Mailgun. Since your From address (abc.com) doesn't include the subdomain mg., Mailgun is confused.

Instead, you need to send the email using the EmailMultiAlternatives object and specify the Email Sender Domain like so:

from django.core.mail import EmailMultiAlternatives

msg = EmailMultiAlternatives("Subject", "text body",
                             "[email protected]", ["[email protected]"])
msg.esp_extra = {"sender_domain": "mg.abc.com"}

msg.send()

Don't forget the brackets in your To field, as this needs to be a tuple or list even if you're only sending it to one recipient.

For more information, see Anymail docs on esp_extra.

Solution 2

I got the same error when I copy-pasted the curl example from Mailgun help page.

My domain was set to EU region, and I had to set the api domain to api.eu.mailgun.net instead of api.mailgun.net.

Boom! Working! :)

Solution 3

I am using the EU region with Mailgun and have run into this problem myself. My implementation is a Node.js application with the mailgun-js NPM package.

EU Region Implementation:

const mailgun = require("mailgun-js");
const API_KEY = "MY_API_KEY";   // Add your API key here
const DOMAIN = "my-domain.com"; // Add your domain here
const mg = mailgun({
    apiKey: API_KEY,
    domain: DOMAIN,
    host: "api.eu.mailgun.net"  // -> Add this line for EU region domains
});
const data = {
    from: "Support <[email protected]>",
    to: "[email protected]",
    subject: "Hello",
    text: "Testing some Mailgun awesomness!"
};
mg.messages().send(data, function(error, body) {
    if (error) {
        console.log(error);
    } else {
        console.log(body);
    }
});

Further options for the mailgun() constructor can be found here.

Thought I'd share a full answer for anybody that's still confused. Additionally, Mailgun Support was kind enough to supply the following table as a reference guide: enter image description here

Solution 4

IF:

  • your domain is an EU domain AND
  • you're using django-anymail as in Rob's answer above

THEN the ANYMAIL setting (in your Django project settings) should specify the API_URL to be the EU one, example:

ANYMAIL = {
    'MAILGUN_API_KEY': '<MAILGUN_API_KEY>',
    'MAILGUN_SENDER_DOMAIN': 'abc.eu',
    'MAILGUN_API_URL': 'https://api.eu.mailgun.net/v3'  # this line saved me!
}

Before adding the MAILGUN_API_URL I was getting this error:

AnymailRequestsAPIError: Sending a message to [email protected] from [email protected] <[email protected]>
Mailgun API response 404 (NOT FOUND):
{
  "message": "Domain not found: mailgun.abc.eu"
}

Solution 5

Struggled for days with correct DNS settings and finally found as @wiktor said, i needed to add "eu" to api endpoint to make it work. Its actually also documented here: https://documentation.mailgun.com/en/latest/api-intro.html#mailgun-regions

Sorry for replying as an answer, dont have enough rep to add comment :(

Share:
12,730

Related videos on Youtube

sudshekhar
Author by

sudshekhar

Learning stuff

Updated on June 04, 2022

Comments

  • sudshekhar
    sudshekhar almost 2 years

    I am trying to setup emails with my own website. Let's say the domain name is abc.com.

    The nameserver in use is digital ocean and I also have a gmail account linked to the same (say using [email protected]).

    While setting up things with mailgun, I used mg.abc.com (as they said it would also let me email using the root domain). The verification step is done and I can send email using [email protected].

    However, trying to use the root domain ([email protected]) gives the following error:

    AnymailRequestsAPIError: Sending a message to [email protected] from [email protected]
    ESP API response 404:
    {
    "message": "Domain not found: abc.com"
    }
    

    How do I resolve this issue?

  • Rob
    Rob over 7 years
    Please note, a new setting is being added to AnyMail that makes this more straight-forward. See comments in this issue.
  • Nick
    Nick about 5 years
    You absolute legend! Can't see this documented anywhere.
  • eighilaza
    eighilaza about 5 years
    Thank you! Where did you find the documentation for it?
  • Stuck
    Stuck almost 5 years
    Thanks! The curl example of their docs also includes multiple to fields.
  • henk.io
    henk.io almost 5 years
    Thank you for this. I was pulling out my hair trying to figure out why this is not working. Adding the host property fixed it for me.
  • Jean Eric
    Jean Eric almost 5 years
    Thanks had spent days looking for an answer
  • Mel Macaluso
    Mel Macaluso almost 5 years
    I owe you a pint
  • Nikita Petrov
    Nikita Petrov over 4 years
    Got the same situation today. Almost a year has passed, and they still haven't updated the example generator.
  • Nik K
    Nik K over 4 years
    Mailglum are outsourcing their technical support to the crowd: "For technical questions we recommend asking the community on Stack Overflow."
  • Goddak
    Goddak over 4 years
    Absolute legend, took about an hour to find this but solved all hy issues in a single line of code (the fact that EU domains need the host property in the config is not obvious!)
  • cloudworks
    cloudworks over 4 years
    Thanks! Same experience here: didn't realise the host property defaults to the US domain, so I was getting "domain not found' until I added it with along with the EU mailgun host.
  • Kossi D. T. S.
    Kossi D. T. S. over 4 years
    Finally: the host key!! - Thanks! It's always a great idea to read the package documentation. It would have saved me hours!
  • kierandes
    kierandes about 4 years
    Thank you, spot on, fixed my problem too.
  • Ajay Makwana
    Ajay Makwana about 4 years
    Life saver answer!
  • Abdul Maye
    Abdul Maye about 4 years
    Legend, you've just saved me a lot of time and frustration!
  • Abner
    Abner almost 4 years
    Save my day. Tks a lot
  • Dimitri Kopriwa
    Dimitri Kopriwa almost 4 years
    Well, to me it seemed to be this, but now the tutorial shows mxa.eu.mailgun.org and mxb.eu.mailgun.org. instead of api.mailgun.net, and I wonder, what is now the right behavior, are your api domain outdated ?
  • Patrik Melander
    Patrik Melander over 3 years
    Thank you! I was pulling my hair on this one. Adding the host solved the problem.
  • highlytrainedbadger
    highlytrainedbadger about 3 years
    You are the best!