2016-12-02 27 views
-1

我正在使用nodemail npm軟件包。無法在nodejs中發送電子郵件

我可以這樣來配置的選項:

function feedback(req, res, next){ 
    console.log('feed back given....', req.body); 
    smtpTrans = nodemailer.createTransport('SMTP', { 
     service: 'Gmail', 
     host: 'smtp.gmail.com', 
     port: 587, 
     secure: false, 
     ignoreTLS: false, 
     tls: { rejectUnauthorized: true }, 
     debug: false, 
     auth: { 
      user: "[email protected]", 
      pass: "xxxxxx" 
     } 
    }); 

    //Mail options 
    mailOpts = { 
     from: from: req.body.email, 
     to: '[email protected]', 
     subject: 'EMAIL FROM Rsc-student: ' + req.body.subject, 
     text: req.body.message 
    }; 

    smtpTrans.sendMail(mailOpts, function (error, response) { 
     //Email not sent 
     if (error) { 
      res.send(error); 
      console.log('error sending mail'); 
     } 
     else { 
      res.send(response); 
      console.log('success sending mail'); 
     } 
    }); 
} 

如果我沒看錯,我正確,但是仍配置無法發送郵件。它的印刷錯誤的情況下

+0

可以分享'錯誤'嗎? – Bhavana

+0

'''from:from:req.body.email,'''確保這一行是正確的! – bharadhwaj

+0

來自:來自:req.body.email,這條線從TO-改變:req.body.email – AJS

回答

1

刪除多餘from:mailOpts

1

按照此3個步驟:

  1. 登錄到您的Gmail帳戶。

  2. 關注此鏈接allow gmail to send mail over less secure app

  3. 選擇選項。

這對我的作品。我希望它能幫助你。

+0

它s已經在用較不安全的模式 – kittu

+0

你得到什麼錯誤,請分享。 –

+0

它只是在if條件下打印控制檯 – kittu