Nodemailer和Mailgun

当使用带有Mailgun的Nodemailer时,我得到一个authentication错误。 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地址时,它是完美的。

你不能用smtp传输使用api密钥。

转到mailgun控制台,从域configuration抓取smtp凭据,并使用这些。

您可以使用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'}} 
 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); } });