Mailgun Domain not found: abc.com

前端 未结 7 1092
遇见更好的自我
遇见更好的自我 2021-02-07 00:17

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 accou

相关标签:
7条回答
  • 2021-02-07 00:25

    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", "contact@abc.com",
              ["to@example.com"],)
    

    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",
                                 "contact@abc.com", ["to@example.com"])
    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.

    0 讨论(0)
  • 2021-02-07 00:29

    I found my fix with this change:

    ANYMAIL = {
       ...
       'MAILGUN_SENDER_DOMAIN': 'mydomain.com', # Using the sending domain in Mailgun
    }
    
    0 讨论(0)
  • 2021-02-07 00:30

    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 :(

    0 讨论(0)
  • 2021-02-07 00:32

    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 xxx@yyy.com from noreply@abc.eu <noreply@abc.eu>
    Mailgun API response 404 (NOT FOUND):
    {
      "message": "Domain not found: mailgun.abc.eu"
    }
    
    0 讨论(0)
  • 2021-02-07 00:33

    I had the same problem: 404 error, domain not found.

    The cause The EU region selection for the domain on Mailgun

    The solution Change the region from EU back to the default of US.

    Since I had not used the domain at all up to this point, I simply deleted it, re-added it, then changed my TXT, MX and CNAME records (for example, mailgun.org instead of eu.mailgun.org) at the domain registrar (which was GoDaddy in my case).

    0 讨论(0)
  • 2021-02-07 00:45

    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 <support@my-domain.com>",
        to: "recipient@example.com",
        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:

    0 讨论(0)
提交回复
热议问题