4

将 Nodemailer 与 Mailgun 一起使用时出现身份验证错误。Nodemailer 文档指出该库与 Mailgun SMTP 配合得很好,但在运行我的应用程序时我不断收到此错误:

{ [AuthError: Invalid login - *** *.*.* Mailgun is not loving your login or password]
  name: 'AuthError',
  data: '*** *.*.* Mailgun is not loving your login or password',
  stage: 'auth' }

这就是我设置运输的方式:

@Transport = nodemailer.createTransport("SMTP",
     service: "Mailgun"
     auth:
         user: "api"
         pass: "**********************"
)

我 100% 确定我的 api 密钥是正确的。我还缺少其他要求吗?

就其价值而言,当我使用 Gmail 地址时,它可以完美运行。

4

3 回答 3

9

您不能将 api 密钥与 smtp 传输一起使用。

转到 mailgun 控制台并从域配置中获取 smtp 凭据并使用它们。

于 2014-03-27T09:41:58.380 回答
4

您可以使用https://github.com/orliesaurus/nodemailer-mailgun-transport使用 API 而不是 SMTP 发送电子邮件。

var nodemailer = require('nodemailer');
var mg = require('nodemailer-mailgun-transport');

var auth = {  auth: {
api_key: 'key-1234123412341234',
domain: 'one of your domain names listed at your https://mailgun.com/app/domains'}}
于 2015-10-29T11:09:45.920 回答
0
var nodemailer = require('nodemailer');
var mg = require('nodemailer-mailgun-transport');

// This is your API key that you retrieve from www.mailgun.com/cp (free up to 10K monthly emails)
var auth = {enter code here
  auth: {`enter code here`
    api_key: 'key-1234123412341234',
    domain: 'one of your domain names listed at your https://mailgun.com/app/domains'
  }
}

var nodemailerMailgun = nodemailer.createTransport(mg(auth));

nodemailerMailgun.sendMail({
  from: 'myemail@example.com',
  to: 'recipient@domain.com', // An array if you have multiple recipients.
  cc:'second@domain.com',
  bcc:'secretagent@company.gov',
  subject: 'Hey you, awesome!',
  'h:Reply-To': 'reply2this@company.com',
  //You can use "html:" to send HTML email content. It's magic!
  html: '<b>Wow Big powerful letters</b>',
  //You can use "text:" to send plain-text content. It's oldschool!
  text: 'Mailgun rocks, pow pow!'
}, function (err, info) {
  if (err) {
    console.log('Error: ' + err);
  }
  else {
    console.log('Response: ' + info);
  }
});
于 2017-02-23T09:16:41.270 回答