gpt4 book ai didi

node.js - 无法使用 Nodemailer 和 Node.js 发送邮件

转载 作者:搜寻专家 更新时间:2023-11-01 00:28:59 26 4
gpt4 key购买 nike

我无法使用 Node.js 发送邮件。我收到以下错误。

{
"error": {
"code": "EAUTH",
"response": "534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvp\n534-5.7.14 j_smRtzyG0TYeMSMFUYlhfCGtpt9DmDE4ZR140rMTKNkk0ZwgtIEQ6Kik51kVBedggHrBA\n534-5.7.14 3mM-ha-68KYhP-IPiHTVQkjUj6HlwdSciwJUgyRqIYKTxTtA9N96CmRzCRiPpIPMf6UGu3\n534-5.7.14 ismcOTMvxqQK2naujp_fgkbLjzwPMj47j5cOoaWdIkdwy4qmqMXnw8ib3sdkRfBeUgjVGB\n534-5.7.14 iiSXqql1vBLMkKnk_HNyGdeQu8OwI> Please log in via your web browser and\n534-5.7.14 then try again.\n534-5.7.14 Learn more at\n534 5.7.14 https://support.google.com/mail/answer/78754 k97sm25351307qkh.29 - gsmtp",
"responseCode": 534,
"command": "AUTH PLAIN"
}
}

这是我的代码:

    var nodemailer = require("nodemailer");
var smtpTransport = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'subhrajyoti@gmail.com',
pass: '********'
}
});
rand=crypto.randomBytes(20).toString('hex');
host=req.get('host');
link="http://"+req.get('host')+"/api/users/verify?id="+rand;

mailOptions={
from: "subhrajyotipradhan@gmail.com",
to : email,
subject : "Please confirm your Vodex account",
html : "Hello,<br> Please Click on the link to verify your Account.<br><a href="+link+">Click here to verify</a>"
}
smtpTransport.sendMail(mailOptions,function(error, response){
if (error) {
var data={'error':error};
res.send(data);
}else{
db.f_user_login.update({_id : docs._id },{$set:{verification_id:rand}},function(err,doc){
if (!err) {
var edata=[{"email": docs.email,"dob": docs.dob,"created_date":docs.created_date ,"id": docs._id,"updated_date":docs.updated_date}];
var data={"statusCode": 200,"data":edata ,"message": "The user registered successfull and an email is sent to your registered email for account verification."};
res.send(data);
}
})
}
})

此代码适用于 localhost:8989 但现在我已将代码部署到 Heroku 中,我的 URL 如下所示 https://node-fgdp.herokuapp.com/api/用户/注册。在这里我无法发送邮件并收到上述错误。我需要使用 nodemailer 和 Node.js 发送邮件。

最佳答案

作为安全预防措施,Google 可能会要求您在登录新设备或应用程序时完成称为解锁验证码的额外步骤。

您可能需要手动允许访问您的 Google 帐户

使用浏览器登录到您的 Google 帐户,然后访问下面的链接将其解锁: https://accounts.google.com/DisplayUnlockCaptcha

点击允许按钮后,您应该会看到消息:

Account access enabled. Please try signing in to your Google account again from your new device or application.

引用:
https://support.google.com/mail/answer/7126229?visit_id=1-636373008143011090-3861871695&rd=2#cantsignin

关于node.js - 无法使用 Nodemailer 和 Node.js 发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45457811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com