【问题标题】:How can I use a relative path for a nodemailer attachment?如何为 nodemailer 附件使用相对路径?
【发布时间】:2018-09-02 23:52:19
【问题描述】:

我正在使用 html-pdf 转换器插件将 HTML 页面转换为 PDF 文件。此插件将 PDF 保存到下载文件夹。

我可以像这样将 PDF 附加到 nodemailer 电子邮件中:

attachments: [{
    filename: 'transportpdf.pdf',
    path: '/Users/green/downloads/transportpdf.pdf',
    contentType: 'application/pdf'
}]

但是,路径是静态的。不同的用户可以将他们的下载文件夹放在不同的位置。有没有办法在我不必使用静态文件地址的情况下缓解这个问题?

【问题讨论】:

    标签: javascript node.js npm nodemailer html2pdf


    【解决方案1】:

    您可以使用:path.relative

    var relativePath = path.relative(process.cwd(), someFilePath);
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-16
      • 1970-01-01
      • 2016-08-18
      相关资源
      最近更新 更多