Search code examples
node.jsnodemailerzoho

Zoho mail says 535 Authentication Failed in Node Js


I am creating an Application using Node Express and MongoDB. After user creation a successful mail want to send to the user. I am using zohomail and can able to use those username and password to login zohomail online. But when I try to send mail I got an error as

  code: 'EAUTH',
  response: '535 Authentication Failed',
  responseCode: 535,
  command: 'AUTH PLAIN'

This is my code

helped snippet from

if (user) {
  var transporter = nodemailer.createTransport({
    host: 'smtp.zoho.com',
    port: 465,
    secure: true, // use SSL
    auth: {
      user: '[email protected]',  //zoho username
      pass: 'password'  //zoho password## Heading ##
    }
  });

  var mailOptions = {
    from: '[email protected]',
    to: req.body.email,
    subject: 'Created Successfully',
    html: '<h1>Hi ' + req.body.fname + ',</h1><p>You have successfully created.</p>'
  };

  transporter.sendMail(mailOptions, function(error, info) {
    if (error) {
      console.log(error);
    } else {
      res.status(200).send(setting.status("User created Successfully, Please Check your Mail"))
    }
  });
}

Solution

  • Thank you Nguyen Manh Tung

    As said in comment.

    I had enabled 2 Factor Authentication (2FA) in Zoho mail.

    So, I login my account here and go to the Two Factor Authentication and get Application specific password.

    After that I used the application specific password instead of zoho mail password in Node Js.

    if (user) {
      var transporter = nodemailer.createTransport({
        host: 'smtp.zoho.com',
        port: 465,
        secure: true, // use SSL
        auth: {
          user: '[email protected]',  //zoho username
          pass: 'application specific password'  //Not zoho mail password because of 2FA enabled
        }
      });
    
      var mailOptions = {
        from: '[email protected]',
        to: req.body.email,
        subject: 'Created Successfully',
        html: '<h1>Hi ' + req.body.fname + ',</h1><p>You have successfully created.</p>'
      };
    
      transporter.sendMail(mailOptions, function(error, info) {
        if (error) {
          console.log(error);
        } else {
          res.status(200).send(setting.status("User created Successfully, Please Check your Mail"))
        }
      });
    }