I am new at node js. I want to make a contact form using nodemailer but i am getting an error message repeatedly and this is like username and pass are not accepted . I am trying to fix the problem but i cant . google less secure apps doesnot working..Here is my code and console error.
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 a2-20020a17090a70c200b001e2a36fb4aasm4621401pjm.43 - gsmtp
at SMTPConnection._formatError (C:\Users\Asus\Documents\online education\node_modules\nodemailer\lib\smtp-connection\index.js:784:19)
at SMTPConnection._actionAUTHComplete (C:\Users\Asus\Documents\online education\node_modules\nodemailer\lib\smtp-connection\index.js:1536:34)
at SMTPConnection.<anonymous> (C:\Users\Asus\Documents\online education\node_modules\nodemailer\lib\smtp-connection\index.js:540:26)
at SMTPConnection._processResponse (C:\Users\Asus\Documents\online education\node_modules\nodemailer\lib\smtp-connection\index.js:947:20)
at SMTPConnection._onData (C:\Users\Asus\Documents\online education\node_modules\nodemailer\lib\smtp-connection\index.js:749:14)
at TLSSocket.SMTPConnection._onSocketData (C:\Users\Asus\Documents\online education\node_modules\nodemailer\lib\smtp-connection\index.js:189:44)
at TLSSocket.emit (events.js:400:28)
at addChunk (internal/streams/readable.js:290:12)
at readableAddChunk (internal/streams/readable.js:265:9)
at TLSSocket.Readable.push (internal/streams/readable.js:204: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 a2-20020a17090a70c200b001e2a36fb4aasm4621401pjm.43 - gsmtp',
responseCode: 535,
command: 'AUTH PLAIN'
}
const express= require('express');
const app=express();
const nodemailer = require('nodemailer');
const PORT=process.env.PORT || 5000;
app.use(express.static('public'));
app.use(express.json())
app.get('/',(req,res)=>{
res.sendFile(__dirname + '/public/contact.html');
});
app.post('/',(req,res)=>{
console.log(req.body);
const transporter= nodemailer.createTransport({
service:'gmail',
auth: {
user:'tr8622043',
pass: 'trisha082215'
},
});
const mailOptions={
from: req.body.email,
to:'tr8622043@gmail.com',
subject:`Message from ${req.body.email} : ${req.body.subject} `,
text: req.body.message
}
transporter.sendMail(mailOptions,(error,info)=>{
if(error){
console.log(error);
res.send('error');
}else{
console.log('Email sent:'+ info.response);
res.send('successful');
}
})
})
app.listen(PORT,()=>{
console.log(`Server running on port ${PORT}`)
})