如何在此节点邮件功能中添加png上传功能?

时间:2019-07-03 09:39:15

标签: node.js express nodemailer

我们正在尝试在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格式呢? 这是附加图像的正确方法吗?

0 个答案:

没有答案