我正在使用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');
}
});
}
如果我沒看錯,我正確,但是仍配置無法發送郵件。它的印刷錯誤的情況下
可以分享'錯誤'嗎? – Bhavana
'''from:from:req.body.email,'''確保這一行是正確的! – bharadhwaj
來自:來自:req.body.email,這條線從TO-改變:req.body.email – AJS