我当前正在尝试使nodemailer在本地工作,但是我一直遇到连接超时错误。我尝试了多种其他方式,甚至尝试了其他代码段,但它对我没有用。
app.post('/contact/send', (req,res)=>{
let transporter = nodemailer.createTransport({
host: 'gmail.com',
port: 465,
secure: true,
auth: {
xoauth2: xoauth2.createXOAuth2Generator({
user: 'mail@gmail.com',
clientId: 'clientID',
clientSecret:'itsasecret',
refreshToken:'refresh',
accessToken:'access token'
})
},
tls:{
rejectUnauthorized:false
}
});
var mailOptions = {
from: '"Website Contact" <mail@gmail.com>',
to: 'mail@gmail.com',
subject: 'Website Inquiry',
text: 'Name: ' + req.body.name + 'Email: ' + req.body.email + 'Message: '+req.body.text,
html: '<p>You have a submission with the following details: </p><ul><li>Name: '
+ req.body.name + '</li><li>Email: '
+ req.body.email + "</li><li>Message: "
+ req.body.message + "</li></ul>"
};
transporter.sendMail(mailOptions, (err, info)=>{
if(err){
console.log(err);
res.redirect('/');
} else {
console.log('Message sent');
res.render('/contact');
}
})
})
这是我收到的错误:
{ Error: connect ETIMEDOUT 172.217.0.37:587
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)
code: 'ECONNECTION',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '172.217.0.37',
port: 587,
command: 'CONN' }
有什么帮助或指导吗?