2017-09-13 93 views
0

嗨这里是我的代码我试图通过nodemailer模块发送邮件 我通过POSTMAN工具访问它。nodemailer不能发送邮件到指定收据通过gmail

 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: '[email protected]', 
       pass: 'my original password' 
       } 
      }); 
      var mailOptions = { 
       from: 'Ravi Kota <[email protected]>', 
       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 
在上面的代码响应产生

是我seperately创建的显示结果

虽然我执行我下面的错误遇到中间件

{ 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
var mailOptions = { 
      from: 'Ravi Kota <[email protected]>', 
      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`}; 
+0

三江源维涅什它得到有效解决 – ravi

0

变更to: 'foundUser.email'

to: foundUser.email

+0

太感谢你了它得到了解决@灵魂行者 – ravi