无法使用 Nodemailer 和 Node.js 发送邮件
Could not send the mail using Nodemailer and Node.js
我无法使用 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/users/signup
。在这里我无法发送邮件并收到上述错误。我需要使用 nodemailer 和 Node.js 发送邮件。
作为一项安全预防措施,Google 可能会要求您在登录新设备或应用程序时完成称为解锁验证码 的额外步骤。
您可能需要手动允许访问您的 Google 帐户。
使用浏览器登录您的 Google 帐户,然后访问下面的 link 将其解锁:
https://accounts.google.com/DisplayUnlockCaptcha
单击 允许 按钮后,您应该会看到消息:
Account access enabled. Please try signing in to your Google account again from your new device or application.
我无法使用 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/users/signup
。在这里我无法发送邮件并收到上述错误。我需要使用 nodemailer 和 Node.js 发送邮件。
作为一项安全预防措施,Google 可能会要求您在登录新设备或应用程序时完成称为解锁验证码 的额外步骤。
您可能需要手动允许访问您的 Google 帐户。
使用浏览器登录您的 Google 帐户,然后访问下面的 link 将其解锁: https://accounts.google.com/DisplayUnlockCaptcha
单击 允许 按钮后,您应该会看到消息:
Account access enabled. Please try signing in to your Google account again from your new device or application.