大家下午好,我有此代码
// Bol Upload Page
router.post('/bolUpload', ensureAuthenticated, async (req, res) => {
try {
var form = new formidable.IncomingForm();
form.parse(req);
form.on('fileBegin', async (name, file) => {
file.path = __dirname + '/../public/bol/' + file.name;
//Pulls previous expense data
await CheckCall.find({truckNumber: req.user.truckNumber, type: 'Depart from Consignee'}).sort({date: -1}).limit(1).exec(async (err,docs) => {
checkCallArray = docs;
await CheckCall.find({truckNumber: req.user.truckNumber, type: 'Arrive at Consignee'}).sort({date: -1}).limit(1).exec(async (err, docs2) =>{
checkCallArray2 = docs2;
checkCallArray.forEach(function(docs){
checkCallArray2.forEach(function(docs2){
form.on('file', function (name, file){
console.log('Uploaded ' + file.name);
transporter.sendMail({
to: 'test@gmail.com',
subject: docs.loadNumber + ' has departed From Consignee on truck #' + req.user.truckNumber,
html: `<title>Depart from Consignee Check Call for ${req.user.truckNumber}</title>
<h4> Submitting user is ${req.user.email}</h4>
<table>
<tr>
<th>Load Number:</th>
<th>Truck Number:</th>
<th>Arrival Date:</th>
<th>Arrival Trailer:</th>
<th>Departure Trailer:</th>
<th>Departure Date:</th>
<th>Seal Number:</th>
<th>Last Trailer Inspection Date:</th>
<th>Tractor Mileage:</th>
</tr>
<tr>
<td>${docs.loadNumber}</td>
<td>${docs.truckNumber}</td>
<td>${docs2.date}</td>
<td>${docs.arrivalTrailer}</td>
<td>${docs.departureTrailer}</td>
<td>${docs.date}</td>
<td>${docs.seal}</td>
<td>${docs.lastInspection}</td>
<td>${docs.tractorMileage}</td>
</tr>
</table>`,
attachments: [{
path: __dirname + '/../public/bol/' + file.name
}]
});
});
});
});
});
});
});
req.flash('success_msg', 'Your BOL has been submitted. Thank you :D');
res.redirect('/dfConsignee');
}
catch (e){
res.send('error_msg');
console.log(e);
}});
当我在本地环境中运行此代码时,它会毫无问题地发送带有附件的电子邮件。但是,一旦我将此文件上传到服务器,它就不会发送电子邮件。我检查了文件位置,并上传了文件。
是什么导致电子邮件无法发送?为什么在本地而不是在生产中起作用?
提前谢谢大家:D