简体   繁体   English

Nodemailer和Mailgun

[英]Nodemailer and Mailgun

I'm getting an authentication error when using Nodemailer with Mailgun. 将Nodemailer与Mailgun一起使用时,出现验证错误。 Nodemailer docs state that the library works nicely with Mailgun SMTP, but I keep getting this error when running my app: 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' }

This is how I set up my transport: 这是我设置交通工具的方式:

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

I'm 100% sure my api key is correct. 我100%确定我的api密钥正确。 Are there any other requirements I'm missing? 我还有其他要求吗?

For what it's worth, it works perfectly when I use a Gmail address. 物有所值,当我使用Gmail地址时,它可以完美工作。

you cannot use api key with smtp transport. 您不能在SMTP传输中使用api密钥。

Go to mailgun console and grab smtp credentials from domain config and use those. 转到mailgun控制台,并从域配置中获取smtp凭据,然后使用这些凭据。

You can use https://github.com/orliesaurus/nodemailer-mailgun-transport to send emails using the API, rather than 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);
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM