Node.js and Nodemailer: Can we attached PDF documents to emails?

杀马特。学长 韩版系。学妹 提交于 2019-12-03 13:46:33
Vishnu

Yes you can. You have to add the path of the file which you are trying to attach.

transporter.sendMail({
  from: 'foo@bar.com',
  to: 'bar@foo.com',
  subject: 'An Attached File',
  text: 'Check out this attached pdf file',
  attachments: [{
    filename: 'file.pdf',
    path: 'C:/Users/Username/Desktop/somefile.pdf',
    contentType: 'application/pdf'
  }],
  function(err, info) {
    if (err) {
      console.error(err);
      res.send(err);
    } else {
      console.log(info);
      res.send(info);
    }
  }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!