我正在使用Node Express和MongoDB创建一个应用程序。创建用户后,成功的邮件要发送给用户。我正在使用zohomail,可以使用这些用户名和密码在线登录zohomail。但是,当我尝试发送邮件时,出现错误
code: 'EAUTH',
response: '535 Authentication Failed',
responseCode: 535,
command: 'AUTH PLAIN'
这是我的代码
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"))
}
});
}
答案 0 :(得分:1)
如评论中所述。
我在Zoho邮件中启用了2因子验证(2FA)。
因此,我登录我的帐户here并转到“双重身份验证”并获取应用程序专用密码。
之后,我在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"))
}
});
}
答案 1 :(得分:1)
如果您来自印度,请将 smtp.zoho.com
替换为 smtp.zoho.in
,其他内容保持不变。示例如下:
const transporter = nodemailer.createTransport({
host: "smtp.zoho.in",
port: 465,
secure: true,
auth: {
user: process.env.ZOHO_EMAIL,
pass: process.env.ZOHO_PASSWORD,
},
});
答案 2 :(得分:0)
1 /检查您的密码。
2 /检查2要素身份验证
您是否通过Zoho启用了2因子身份验证?
如果启用它,则需要创建应用程序专用密码。