我们正在尝试在nodemailer函数中实现附件功能。这是代码:
app.post('/', (req,res) => {
var data = req.body;
var smtpTransport = nodemailer.createTransport({
service: 'Gmail',
port: 465,
auth: {
user: 'USERNAME',
pass: 'PASSWORD'
}
});
var mailOptions = {
from: data.email,
to: 'ENTER_YOUR_EMAIL',
subject: 'ENTER_YOUR_SUBJECT',
html: `<p>${data.name}</p>
<p>${data.email}</p>
<p>${data.message}</p>`,
attachments:[ { fileName: req.body.title+".jpg", streamSource: fs.createReadStream(req.files.image.path) } ]
};
smtpTransport.sendMail(mailOptions,
(error, response) => {
if(error) {
res.send(error)
}else {
res.send('Success')
}
smtpTransport.close();
});
})
如何在代码的附件部分中让jpg以外的其他png格式呢? 这是附加图像的正确方法吗?