无法使用 MailGun 节点发送电子邮件 API

Unable to send email using MailGun Node API

当尝试使用他们的节点 api 通过 mailgun 发送简单的测试消息时,我没有收到任何错误,但我也没有收到电子邮件,也没有在 mailgun 日志中看到任何响应。

这是我使用的代码...

const mailgun = require('mailgun-js')({
  apiKey: 'XXXXXXXXXX', 
  domain: 'https://api.mailgun.net/v3/XXXXXXXXX'
})

async function sendInvite() { 
  var email = process.argv[process.argv.length - 1]

  const data = {
    from: 'support@acme.com',
    to: email,
    subject: 'Welcome!',
    html: '<p>Welcome!</p><p>You are very special!</p>'
  }

  return new Promise((resolve, reject) => {
    mailgun.messages().send(data, (error, body) => {
      if (error) {
        console.error(error)
        reject(error)
        return
      }
      console.log(`Invite sent to ${email}`)
      console.log(data)
      console.log(body)
      resolve();
    })
  })

}

sendInvite().then(() => console.log('Done')).catch((err) => console.error(err))

您是否已将信用卡附加到 mailGun 帐户?或者,如果您只是需要测试您的逻辑,请在您的帐户 settings 中确认任何电子邮件地址,该地址将收到来自 mailgun

的电子邮件

https://wordpress.org/support/topic/mailgun-http-api-test-failure-status-free-accounts-are-for-test-purposes-only/

我发现我遇到的问题是我传递到 mailgun 的域的格式。

之前我有以下内容:

const mailgun = require('mailgun-js')({
  apiKey: 'XXXXXXXXXX', 
  domain: 'https://api.mailgun.net/v3/XXXXXXXXX'
})

问题是 domain 的值不应包括 URL 的 https://api.mailgun.net/v3/ 部分。相反,它应该只有您的域,例如mail.mydomain.com