我无法使用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中部署了代码,我的网址就像https://node-fgdp.herokuapp.com/api/users/signup
一样。在这里,我无法发送邮件并获得上述错误。我需要使用nodemailer和Node.js发送邮件。
答案 0 :(得分:4)
作为安全预防措施,Google可能会要求您在登录新设备或应用程序时完成名为解锁验证码的其他步骤。
您可能需要手动允许访问您的Google帐户。
使用浏览器登录您的Google帐户,然后访问以下链接解锁: https://accounts.google.com/DisplayUnlockCaptcha
点击允许按钮后,您会看到以下消息:
启用帐户访问权限。请尝试从新设备或应用程序再次登录您的Google帐户。