My Node js code is sending proper email on localhost but in backend there showing email and password not valid ?
const nodemailer = require("nodemailer");
const sendEmail = async (subject, message, send_to, sent_from, reply_to) => {
// Create Email Transporter
const transporter = nodemailer.createTransport({
host: process.env.EMAIL_HOST,
port: 465,
secure: true,
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
});
// Options for sending email
const options = {
from: sent_from,
to: send_to,
reply_to: reply_to,
subject: subject,
html: message,
};
// Check email sent successfully or not
transporter.sendMail(options, function (err, info) {
if (err) {
console.log(err);
} else {
console.log(info);
}
});
};
module.exports = sendEmail;
const transporter = nodemailer.createTransport({
host : imap.gmail.com,
port: 465,
secure:true,
auth : {
user: abc@gmail.com,
pass: abc,
},
});
Use imap.gmail.com as host and use app specific password in your account, the issue might be fixed, for my case it is fixed by changing the host smtp.gmail.com to imap.gmail.com. Above code is an example of how my issue is fixed.