[英]Mailgun domain not found: example.com
I am trying to setup emails with my own website.我正在尝试使用我自己的网站设置电子邮件。 Let's say the domain name is
example.com
.假设域名是
example.com
。
The name server in use is digital ocean and I also have a gmail account linked to the same (say using contact@example.com
).使用的名称服务器是数字海洋,我也有一个链接到相同的 gmail 帐户(例如使用
contact@example.com
)。
While setting up things with mailgun, I used mg.example.com
(as they said it would also let me email using the root domain).在使用 mailgun 进行设置时,我使用
mg.example.com
(因为他们说它也可以让我使用根域发送电子邮件)。 The verification step is done and I can send email using contact@mg.example.com
.验证步骤已完成,我可以使用
contact@mg.example.com
发送电子邮件。
However, trying to use the root domain ( contact@example.com
) gives the following error:但是,尝试使用根域 (
contact@example.com
) 会出现以下错误:
AnymailRequestsAPIError: Sending a message to me@gmail.com from contact@example.com
ESP API response 404:
{
"message": "Domain not found: example.com"
}
How do I resolve this issue?我该如何解决这个问题?
I got the same error when I copy-pasted the curl
example from Mailgun help page.当我从 Mailgun 帮助页面复制粘贴
curl
示例时,我遇到了同样的错误。
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
.我的域设置为欧盟地区,我必须将 api 域设置为
api.eu.mailgun.net
而不是api.mailgun.net
。
Boom!繁荣! Working!
在职的! :)
:)
I am using the EU region with Mailgun and have run into this problem myself.我正在使用带有 Mailgun 的欧盟地区,我自己也遇到了这个问题。 My implementation is a
Node.js
application with the mailgun-js
NPM package .我的实现是一个带有
mailgun-js
NPM 包的Node.js
应用程序。
EU Region Implementation:欧盟地区实施:
const mailgun = require("mailgun-js");
const API_KEY = "MY_API_KEY"; // Add your API key here
const DOMAIN = "my-domain.example"; // 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.example>",
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 .可以在此处找到
mailgun()
构造函数的更多options
。
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:
此外,Mailgun Support 非常友好地提供了下表作为参考指南:
IF
: IF
:
django-anymail
as in Rob's answer abovedjango-anymail
,如上面 Rob 的回答THEN
the ANYMAIL
setting (in your Django project settings) should specify the API_URL
to be the EU one, example: THEN
设置(在您的 Django 项目设置中)应将ANYMAIL
API_URL
为欧盟之一,例如:
ANYMAIL = {
'MAILGUN_API_KEY': '<MAILGUN_API_KEY>',
'MAILGUN_SENDER_DOMAIN': 'example.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:在添加
MAILGUN_API_URL
之前,我收到了这个错误:
AnymailRequestsAPIError: Sending a message to xxx@example.com from noreply@example.eu <noreply@example.eu>
Mailgun API response 404 (NOT FOUND):
{
"message": "Domain not found: mailgun.example.eu"
}
Update 8/22/16: Anymail has been updated to take a new MAILGUN_SENDER_DOMAIN in settings.py
. 2016 年 8 月 22 日更新: Anymail 已更新为在
settings.py
中采用新的 MAILGUN_SENDER_DOMAIN。 See version .5+ docs.请参阅版本 .5+ 文档。
-- 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: -原始答案您没有发布有关如何发送电子邮件的代码,但您可能正在尝试使用简单的 send_mail() 函数进行发送:
from django.core.mail import send_mail
send_mail("Subject", "text body", "contact@abc.example",
["to@example.com"],)
When you use this method, Anymail pulls the domain out of your From address and tries to use this with Mailgun.当您使用此方法时,Anymail 会从您的发件人地址中提取域并尝试将其与 Mailgun 一起使用。 Since your From address (
abc.example
) doesn't include the subdomain mg., Mailgun is confused.由于您的发件人地址 (
abc.example
) 不包含子域 mg.,因此 Mailgun 很困惑。
Instead, you need to send the email using the EmailMultiAlternatives
object and specify the Email Sender Domain like so:相反,您需要使用
EmailMultiAlternatives
对象发送电子邮件并指定电子邮件发件人域,如下所示:
from django.core.mail import EmailMultiAlternatives
msg = EmailMultiAlternatives("Subject", "text body",
"contact@abc.example", ["to@example.com"])
msg.esp_extra = {"sender_domain": "mg.abc.example"}
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.不要忘记 To 字段中的括号,因为这需要是一个元组或列表,即使您只是将它发送给一个收件人。
For more information, see Anymail docs on esp_extra .有关更多信息,请参阅 esp_extra 上的Anymail文档。
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.用正确的 DNS 设置挣扎了好几天,最后发现正如@wiktor 所说,我需要将“eu”添加到 api 端点以使其工作。 Its actually also documented here: https://documentation.mailgun.com/en/latest/api-intro.html#mailgun-regions
它实际上也记录在这里: https ://documentation.mailgun.com/en/latest/api-intro.html#mailgun-regions
Sorry for replying as an answer, dont have enough rep to add comment :(很抱歉作为答案回复,没有足够的代表来添加评论:(
I had the same problem: 404 error, domain not found.我遇到了同样的问题:404 错误,找不到域。
The cause The EU region selection for the domain on Mailgun原因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).由于到目前为止我还没有使用过该域,所以我只是将其删除,重新添加,然后在域名注册商(在我的例子中是 GoDaddy)。
I found my fix with this change:我找到了解决此更改的方法:
ANYMAIL = {
...
'MAILGUN_SENDER_DOMAIN': 'example.com', # Using the sending domain in Mailgun
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.