首页 > 解决方案 > 我可以使用 mailgun 中的沙箱域发送电子邮件,但不能使用经过验证的真实域

问题描述

我在托管我的网站的 netlify 上添加了所需的 dns 配置,当我转到我的域的 DNS 记录时,所有字段(TXT、MX、CNAME)上的所有刻度都是绿色的,所以我知道该域已经过验证。但是,我在发送消息时无法使用域并收到此错误:

Error: Forbidden
    at IncomingMessage.<anonymous> (C:\Users\MSI\Desktop\mail\node_modules\mailgun-js\lib\request.js:327:17)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1220:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  statusCode: 401
}

这是我从 mailgun 文档中复制的代码,并将值更改为我的域和我的 api 密钥:

const mailgun = require('mailgun-js');
const DOMAIN = 'example.com'; 
//The domain is written in the exact same form (not https://example.com)
const api_key = '****************************************';
const mg = mailgun({ apiKey: api_key, domain: DOMAIN });
const data = {
 from: 'Name <myemail@gmail.com>',
 to: 'myemail@gmail.com',
 subject: 'Hello',
 text: 'Testing some Mailgun awesomness!',
};

mg.messages().send(data, (err, body) => {
 if (err) throw err;
  console.log(body);
});

我已经查看了有关此主题的所有 stackoverflow 问题,但似乎仍然没有找到问题所在(同样,上面的代码正在使用沙箱域)。帮助

标签: javascriptnode.jsemaildnsmailgun

解决方案


推荐阅读