我正在尝试使用带有 Gmail 帐户的 Nodemailer 在我的应用程序中设置电子邮件验证。
我的问题是它报告错误,指出我的用户名和密码尚未被接受:
There was an error: Error: Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials a3sm2007362wri.89 - gsmtp
const transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
service: "Gmail",
port: 465,
secure: true,
auth: {
user: process.env.USER,
pass: process.env.PASS,
},
});
transporter.sendMail(
{
from: process.env.USER,
to: email,
subject: subject,
text: text,
},
(error) => {
if (error) {
return console.log("There was an error: " + error);
}
console.log("Email sent successfully");
}
);
我可以确认process.env.USER
and process.env.PASS
是正确的,而且我也允许不太安全的应用程序.
有什么我遗漏/不理解的吗?