当我尝试在部署到Plesk上时使用nodemailer发送电子邮件时,出现此错误EHOSTUNREACH
错误。但是当我在本地测试时不会发生此错误。我知道这意味着没有找到通往主机的路由,但这意味着什么?以及我该如何解决?
var express = require('express');
var path = require('path')
var mailer = require('nodemailer');
var bodyParser = require('body-parser')
const app = express();
app.use(express.static(path.join(__dirname, 'client/build')));
app.use(bodyParser.json())
var transporter = mailer.createTransport({
service: 'gmail',
auth: {
user: 'real.tech.mailer@gmail.com',
pass: 'password'
}
});
var mailOptions = {
from: 'real.tech.mailer@gmail.com',
to: 'mail@adres.com',
subject: 'subject',
text: 'Er is iets misgegaan'
};
app.post('/sendform', (req, res) => {
console.log(req.body)
let response = 'transporter did nothing';
mailOptions.text = JSON.stringify(req.body, null, 2);
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
response = 'Email sent: ' + info.response;
console.log('Email sent: ' + info.response);
}
res.end(response);
});
})
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname+'client/build/index.html'));
})
const port = process.env.PORT || 5000;
app.listen(port)
console.log(`Server Started on ${port}`)