I'm getting an authentication error when using Nodemailer with Mailgun. Nodemailer docs state that the library works nicely with Mailgun SMTP, but I keep getting this error when running my app:
{ [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. Are there any other requirements I'm missing?
For what it's worth, it works perfectly when I use a Gmail address.
I'm getting an authentication error when using Nodemailer with Mailgun. Nodemailer docs state that the library works nicely with Mailgun SMTP, but I keep getting this error when running my app:
{ [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. Are there any other requirements I'm missing?
For what it's worth, it works perfectly when I use a Gmail address.
Share Improve this question asked Mar 20, 2014 at 17:54 Connor BlackConnor Black 7,18112 gold badges40 silver badges71 bronze badges3 Answers
Reset to default 10you cannot use api key with smtp transport.
Go to mailgun console and grab smtp credentials from domain config and use those.
You can use https://github./orliesaurus/nodemailer-mailgun-transport to send emails using the API, rather than 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./app/domains'}}
var nodemailer = require('nodemailer');
var mg = require('nodemailer-mailgun-transport');
// This is your API key that you retrieve from www.mailgun./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./app/domains'
}
}
var nodemailerMailgun = nodemailer.createTransport(mg(auth));
nodemailerMailgun.sendMail({
from: '[email protected]',
to: '[email protected]', // An array if you have multiple recipients.
cc:'[email protected]',
bcc:'[email protected]',
subject: 'Hey you, awesome!',
'h:Reply-To': '[email protected]',
//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);
}
});