0

I am trying to send emails to using nodemailer from my site but it gives me this error

Error: Invalid login: 535-5.7.8 Username and Password not accepted.

and I made sure the password and credentials is accurate. This is my code for setting up nodemailer

function message(merchantEmail, msgTxt){

  var transporter = nodemailer.createTransport({
    host: "smtp.gmail.com",
    secure: true,
    port: 465,
    auth: {
      user: 'kesterdaniel401@gmail.com',
      pass: process.env.PASSWORD
    },
    tls: {
      rejectUnauthorized: false
    }
  });
  
  var mailOptions = {
    from: 'kesterdaniel401@gmail.com',
    to: merchantEmail,
    subject: 'Sending Email using Node.js',
    text: msgTxt
  };
  
  transporter.sendMail(mailOptions, function(error, info){
    if (error) {
      console.log(error);
    } else {
      console.log('Email sent: ' + info.response);
    }
  });
}

module.exports = message

This is where I called the function

        message(productOwner.Email, `You have received an order from ${Buyer.Name} for the product ${product. ProductName}. Please contact the customer as soon as possible. Customer Number is ${Buyer.PhoneNumber}.`)
blocboyx
  • 53
  • 7
  • I also noticed that you're using smtp.gmail.com as your host, this resource can help you check if you've configured it correctly https://miracleio.me/snippets/use-gmail-with-nodemailer/ – FaitAccompli Oct 09 '22 at 09:01
  • Possible duplicate of https://stackoverflow.com/questions/45478293/username-and-password-not-accepted-when-using-nodemailer – FaitAccompli Oct 09 '22 at 09:02

0 Answers0