Zoho 邮件显示 Node Js 中的 535 身份验证失败

tes*_*eam 4 zoho node.js nodemailer

我正在使用 Node Express 和 MongoDB 创建一个应用程序。用户创建成功后,想要发送给用户的邮件。我正在使用 zohomail,可以使用这些用户名和密码在线登录 zohomail。但是当我尝试发送邮件时出现错误

  code: 'EAUTH',
  response: '535 Authentication Failed',
  responseCode: 535,
  command: 'AUTH PLAIN'
Run Code Online (Sandbox Code Playgroud)

这是我的代码

帮助片段来自

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"))
    }
  });
}
Run Code Online (Sandbox Code Playgroud)

tes*_*eam 8

谢谢阮孟东

正如评论中所说。

我在 Zoho 邮件中启用了 2 因素身份验证 (2FA)。

所以,我在这里登录我的帐户并转到双重身份验证并获取应用程序特定密码。

之后,我在 Node Js 中使用了应用程序特定密码而不是 zoho 邮件密码。

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"))
    }
  });
}
Run Code Online (Sandbox Code Playgroud)