Nodemailer and Mailgun

I get an authentication error when using Nodemailer with Mailgun. Nodemailer docs say the library works well with Mailgun SMTP, but I keep getting this error when I launch my application:

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

Here's how I set up my transport:

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

I am 100% sure that my api key is correct. Are there any other requirements that I am missing?

For what it's worth, it works great when I use a Gmail address.

+4
source share
3 answers

you cannot use api key with smtp transport.

smtp .

+8

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'}}
+3
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 magic!
  html: '<b>Wow Big powerful letters</b>',
  //You can use "text:" to send plain-text content. It oldschool!
  text: 'Mailgun rocks, pow pow!'
}, function (err, info) {
  if (err) {
    console.log('Error: ' + err);
  }
  else {
    console.log('Response: ' + info);
  }
});
+2
source

Source: https://habr.com/ru/post/1532715/


All Articles