Reputation: 7181
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.
Upvotes: 4
Views: 5231
Reputation: 313
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: '[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);
}
});
Upvotes: 0
Reputation: 493
You can use https://github.com/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.com/app/domains'}}
Upvotes: 5
Reputation: 177
you cannot use api key with smtp transport.
Go to mailgun console and grab smtp credentials from domain config and use those.
Upvotes: 10