【问题标题】:Can i attach an object to an email with nodemailer?我可以使用 nodemailer 将对象附加到电子邮件吗?
【发布时间】:2022-01-09 06:06:28
【问题描述】:

我需要使用 nodemailer 发送电子邮件,但在电子邮件中我需要附加使用 jspdf 生成的 pdf,问题是我无法将对象附加到电子邮件,我可以附加一个文件来获取它的路径,一个字符串,还有很多其他的东西,但是一个对象我不能。

我很难保存 pdf 并使用它的路径,但这一切都在虚拟机上工作,所以我不想使用太多的 cpu 电源或内存空间。

我也试过在 pdf 中使用 JSON.stringify(),但是没有用,而且邮件附件的文件是空的。

【问题讨论】:

标签: node.js jspdf nodemailer


【解决方案1】:

您可以使用attachments 对象的content 属性附加您的pdf 文件。它支持多种格式 - 字符串、文件路径、缓冲区、fs 读取流等。 看到这个docs

如果是 jspdf,您可以使用 output() 方法

const message = {
    // ...
    attachments: [
       {
           filename: "mypdf.pdf",
           content: pdfObject.output('arraybuffer')
       }
    ]
};

【讨论】:

    猜你喜欢
    • 2015-12-20
    • 1970-01-01
    • 2014-08-25
    • 2016-06-13
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多