6

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: 'sample@sample.com',  //zoho username
      pass: 'password'  //zoho password## Heading ##
    }
  });

  var mailOptions = {
    from: 'sample@sample.com',
    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"))
    }
  });
}
Rastalamm
  • 1,712
  • 3
  • 23
  • 32
test team
  • 677
  • 3
  • 12
  • 27

4 Answers4

11

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: 'sample@sample.com',  //zoho username
      pass: 'application specific password'  //Not zoho mail password because of 2FA enabled
    }
  });

  var mailOptions = {
    from: 'sample@sample.com',
    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"))
    }
  });
}
test team
  • 677
  • 3
  • 12
  • 27
2

1/ Check your password.

2/ Check 2 factor authentication

Did you enable 2 factor authentication with Zoho?

If you enabled it, you need to create application specific password.

  • Yeah my password is ok. And 2FA enables with Google Authenticator. How can I create application specific password? – test team Jan 08 '19 at 03:15
2

If you are from India, replace smtp.zoho.com with smtp.zoho.in keeping other things same. Sample is given below:

const transporter = nodemailer.createTransport({
  host: "smtp.zoho.in",
  port: 465,
  secure: true,
  auth: {
    user: process.env.ZOHO_EMAIL,
    pass: process.env.ZOHO_PASSWORD,
  },
});
xenowits
  • 329
  • 2
  • 7
0

For anyone still facing authentication errors after adding 2 Factor authentication and generating an App password. If you created your Zoho Mail account from the EU please change your host to the following:

host: "smtp.zoho.eu"