I want to send an email from node backend and I am using the nodemailer library for express to achieve that. I have written the following code to configure the transport and other details for nodemailer
let transport = nodemailer.createTransport({
host: 'mail.myrandomhost.in',
port: 587,
tls: {
rejectUnauthorized:false
},
secure: false,
auth: {
user: 'me@myemail.in',
pass: 'Gr3aseMonk3y'
}
});
const message = {
from: 'me@myemail.in',
to: 'youremail@gmail.com',
subject: 'test email',
html: '<h1>Hey</h1><p>This is test <b>Tesla</b> email</p>'
};
transport.sendMail(message, function(err, info) {
if (err) {
console.log('-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=');
console.log("FAILED");
console.log('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
console.log(err)
} else {
console.log('====================================');
console.log("Email sent");
console.log('====================================');
console.log(info);
}
});
When I run this, I get the following error
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
FAILED
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Error: Invalid login: 535 Incorrect authentication data
at SMTPConnection._formatError (/Users/sarthak/Desktop/CodingEnvironments/NodeJS/templates/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
at SMTPConnection._actionAUTHComplete (/Users/sarthak/Desktop/CodingEnvironments/NodeJS/templates/node_modules/nodemailer/lib/smtp-connection/index.js:1523:34)
at SMTPConnection.<anonymous> (/Users/sarthak/Desktop/CodingEnvironments/NodeJS/templates/node_modules/nodemailer/lib/smtp-connection/index.js:550:26)
at SMTPConnection._processResponse (/Users/sarthak/Desktop/CodingEnvironments/NodeJS/templates/node_modules/nodemailer/lib/smtp-connection/index.js:942:20)
at SMTPConnection._onData (/Users/sarthak/Desktop/CodingEnvironments/NodeJS/templates/node_modules/nodemailer/lib/smtp-connection/index.js:749:14)
at TLSSocket.SMTPConnection._onSocketData (/Users/sarthak/Desktop/CodingEnvironments/NodeJS/templates/node_modules/nodemailer/lib/smtp-connection/index.js:195:44)
at TLSSocket.emit (events.js:210:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at TLSSocket.Readable.push (_stream_readable.js:224:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:182:23) {
code: 'EAUTH',
response: '535 Incorrect authentication data',
responseCode: 535,
command: 'AUTH PLAIN'
}
I am using the correct details. How do I solve this?
You entered the wrong data. you must change host
, from
to real addresses. Example:
let transport = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
tls: {
rejectUnauthorized:true
},
secure: false,
auth: {
user: 'yourRealEmail@gmail.com',
pass: 'yourPassword'
}
});
const message = {
from: 'yourRealEmail@gmail.com',
to: 'RealEmailAddress@gmail.com',
subject: 'test email',
html: '<h1>Hey</h1><p>This is test <b>Tesla</b> email</p>'
};
transport.sendMail(message, function(err, info) {
if (err) {
console.log('-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=');
console.log("FAILED");
console.log('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
console.log(err)
} else {
console.log('====================================');
console.log("Email sent");
console.log('====================================');
console.log(info);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.