嗨,这是我的代码,我试图通过nodemailer模块发送邮件 我通过POSTMAN工具访问它。
userRouter.post('/forgetPassword', function(req,res){
userModel.findOne({'email': req.body.email}, function(err,foundUser ){
if(!foundUser){
var myResponse = responseGenerator.generate(true,"please check
your email id", 404 , null);
res.send(myResponse);
}
else if (err) {
var myResponse = responseGenerator.generate(true,"entered wrong
email id", 404 , null);
res.send(myResponse);
}
else{
var transporter = nodemailer.createTransport({
service : "gmail",
auth: {
user: 'kota.raavi@gmail.com',
pass: 'my original password'
}
});
var mailOptions = {
from: 'Ravi Kota <kota.raavi@gmail.com>',
to: 'foundUser.email',
subject: 'Sending Email using Node.js',
text: 'here is the required token by which you can reset your
password and the same will be updated!'
`enter code here`};
transporter.sendMail(mailOptions, function(err, info){
if (err) {
console.log(err);
var myResponse = responseGenerator.generate(true,"entered
coming here wrong email id", 404 , null);
//res.send(myResponse);
} else {
console.log('Email sent: ' + info.response);
//var myResponse = responseGenerator.generate(false,"check
your modified inbox", 200 , info);
//res.send(myResponse);
}
});
}
});
});// end forgetPassrword
上面的代码响应生成器中的是我单独创建的用于显示结果的中间件
当我执行时遇到以下错误
{ Error: No recipients defined
at SMTPConnection._formatError
(C:\weaversdirect\mvcApp2\node_modules\nodemailer\lib\smtp-
connection\index.js:577:19)
at SMTPConnection._setEnvelope
(C:\weaversdirect\mvcApp2\node_modules\nodemailer\lib\smtp-
connection\index.js:786:34)
at SMTPConnection.send
(C:\weaversdirect\mvcApp2\node_modules\nodemailer\lib\smtp-
connection\index.js:408:14)
at sendMessage
(C:\weaversdirect\mvcApp2\node_modules\nodemailer\lib\smtp-
transport\index.js:219:28)
at connection.login.err
(C:\weaversdirect\mvcApp2\node_modules\nodemailer\lib\smtp-
transport\index.js:276:25)
at SMTPConnection._actionAUTHComplete
(C:\weaversdirect\mvcApp2\node_modules\nodemailer\lib\smtp-
connection\index.js:1320:9)
at SMTPConnection._responseActions.push.str
(C:\weaversdirect\mvcApp2\node_modules\nodemailer\lib\smtp-
connection\index.js:349:26)
at SMTPConnection._processResponse
at TLSSocket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at TLSSocket.Readable.push (_stream_readable.js:134:10)
at TLSWrap.onread (net.js:547:20) code: 'EENVELOPE', command: 'API' }
POST /users/forgetPassword - - ms - -
请纠正我在哪里做错了 谢谢
答案 0 :(得分:0)
更改to: 'foundUser.email'
到to: foundUser.email
答案 1 :(得分:0)
var mailOptions = {
from: 'Ravi Kota <kota.raavi@gmail.com>',
to: foundUser.email,
subject: 'Sending Email using Node.js',
text: 'here is the required token by which you can reset your
password and the same will be updated!'
`enter code here`};