I'm trying to send email using nodemailer and below is my code for that...
require('dotenv').config();
const nodemailer=require('nodemailer');
// step 1
let transporter=nodemailer.createTransport({
service: 'gmail',
auth:{
user: process.env.EMAIL,
pass: process.env.PASSWORD
}
});
let mailOptions={
from: 'abc@gmail.com',
to: 'mrinal.annand@gmail.com',
subject: 'Testing and Testing',
text: 'yes,it works'
};
transporter.sendMail(mailOptions,function(err,data){
if(err)console.log('Error Occurs',err);
else console.log('Message sent!!');
})
i am getting this much long error, what i'm doing wrong here. why it is saying username and password not accepted,both my mails are valid and working, password i have given arbitrarily..
Error Occurs Error: Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials x19sm2827077pgk.37 -
gsmtp
at SMTPConnection._formatError (C:\Users\91725\Desktop\sending_mail\node_modules\nodemailer\lib\smtp-connection\index.js:784:19)
at SMTPConnection._actionAUTHComplete (C:\Users\91725\Desktop\sending_mail\node_modules\nodemailer\lib\smtp-connection\index.js:1536:34)
at SMTPConnection.<anonymous> (C:\Users\91725\Desktop\sending_mail\node_modules\nodemailer\lib\smtp-connection\index.js:540:26)
at SMTPConnection._processResponse (C:\Users\91725\Desktop\sending_mail\node_modules\nodemailer\lib\smtp-connection\index.js:947:20)
at SMTPConnection._onData (C:\Users\91725\Desktop\sending_mail\node_modules\nodemailer\lib\smtp-connection\index.js:749:14)
at SMTPConnection._actionAUTHComplete (C:\Users\91725\Desktop\sending_mail\node_modules\nodemailer\lib\smtp-connection\index.js:1536:34)
at SMTPConnection.<anonymous> (C:\Users\91725\Desktop\sending_mail\node_modules\nodemailer\lib\smtp-connection\index.js:540:26)
at SMTPConnection._processResponse (C:\Users\91725\Desktop\sending_mail\node_modules\nodemailer\lib\smtp-connection\index.js:947:20)
at SMTPConnection._onData (C:\Users\91725\Desktop\sending_mail\node_modules\nodemailer\lib\smtp-connection\index.js:749:14)
at TLSSocket.SMTPConnection._onSocketData (C:\Users\91725\Desktop\sending_mail\node_modules\nodemailer\lib\smtp-connection\index.js:189:44)
at TLSSocket.emit (events.js:376:20)
at addChunk (internal/streams/readable.js:309:12)
at readableAddChunk (internal/streams/readable.js:284:9)
at TLSSocket.Readable.push (internal/streams/readable.js:223:10) {
code: 'EAUTH',
response: '535-5.7.8 Username and Password not accepted. Learn more at\n' +
'535 5.7.8 https://support.google.com/mail/?p=BadCredentials x19sm2827077pgk.37 - gsmtp',
responseCode: 535,
command: 'AUTH PLAIN'
}
apparently the username and password of the email are wrong, you should try to login using copy paste with those credentials