here's my UserController.js where i am receiving user email and password as a post request
const User = require('../models/User');
const nodemailer = require('nodemailer');
module.exports.User = (req, res) => {
if(req.body.password != req.body.confirm_password){
res.redirect('back')
}
User.findOne({email: req.body.email}, function(err, user){
//error in creating the user
if(err){console.log('error in creating the user');}
//if user doesnot initially exist in the daatbase
if(!user){
User.create(req.body, function(err, user){
if(err){console.log('error');}
console.log('User created');
})
return res.send('<script>alert("User created")</script>');
}
else{
console.log('User already present in the database');
let mailTransporter = nodemailer.createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
auth: {
email: 'my_email',
pass: 'my_email_password'
}
});
let mailDetails = {
from: 'my_email',
to: req.body.email,
subject: 'from dhruv singhal as a project',
text: 'your data is successfully stored on our database'
};
mailTransporter.sendMail(mailDetails, function(err, data) {
if(err) {
console.log(err);
} else {
console.log('Email sent successfully');
}
});
res.send('<script>alert("your have already got mail from our side")</script>')
}
})
}
i am getting error as :-
/* Error: Missing credentials for "PLAIN" at SMTPConnection._formatError (C:\Users\dhruv singhal\Desktop\web_development_project\node_modules\nodemailer\lib\smtp-connection\index.js:774:19) at SMTPConnection.login (C:\Users\dhruv singhal\Desktop\web_development_project\node_modules\nodemailer\lib\smtp-connection\index.js:438:38) at C:\Users\dhruv singhal\Desktop\web_development_project\node_modules\nodemailer\lib\smtp-transport\index.js:271:32 at SMTPConnection. (C:\Users\dhruv singhal\Desktop\web_development_project\node_modules\nodemailer\lib\smtp-connection\index.js:209:17) at Object.onceWrapper (events.js:421:28) at SMTPConnection.emit (events.js:315:20) at SMTPConnection._actionEHLO (C:\Us enter code here
ers\dhruv singhal\Desktop\web_development_project\node_modules\nodemailer\lib\smtp-connection\index.js:1303:14) at SMTPConnection._processResponse (C:\Users\dhruv singhal\Desktop\web_development_project\node_modules\nodemailer\lib\smtp-connection\index.js:932:20) at SMTPConnection._onData (C:\Users\dhruv singhal\Desktop\web_development_project\node_modules\nodemailer\lib\smtp-connection\index.js:739:14) at TLSSocket.SMTPConnection._onSocketData (C:\Users\dhruv singhal\Desktop\web_development_project\node_modules\nodemailer\lib\smtp-connection\index.js:189:44) at TLSSocket.emit (events.js:315:20) at addChunk (_stream_readable.js:295:12) at readableAddChunk (_stream_readable.js:271:9) at TLSSocket.Readable.push (_stream_readable.js:212:10) at TLSWrap.onStreamRead (internal/stream_base_commons.js:186:23) { code: 'EAUTH', command: 'API' }
i have enabled less secure apps on google please help
complete github code :-https://github.com/dhruv354/form.git*/
Have you done the "Captcha Challenge" on top of enabling the less secure app
?
Instead of email: 'my_email'
I believe you need user: 'my_email'
. See this nodemailer example.
As mentioned in the other answer: before sending from your app for the first time, click this from the relevant Google account: https://accounts.google.com/DisplayUnlockCaptcha
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.