相关疑难解决方法(0)

Node.js SendGrid 如何附加 PDF

我正在使用SendGrid在我的 Node.js 应用程序中发送电子邮件。我尝试附加 pdf 的每个组合都以我附加的 pdf 不可读而告终。

我试过了:

fs.readFile('public_html/img/Report.pdf',function(err,data){
    var base64data = new Buffer(data).toString('base64');

    sendgrid.send({
        to        : hexDecode(_.e),
        from      : 'xxxxxxxxx@gmail.com',
        subject   : 'Report',
        
        files      : [{filename:'Report.pdf',content:'data:application/pdf;base64,'+base64data}],
        // files   : [{filename:'Report.pdf',contentType:'data:application/pdf',url:'public_html/img/'Report.pdf'}],
        // files   : [{filename:'Report.pdf',url:'public_html/img/'Report.pdf'}],
        html       : 'bla bla'
Run Code Online (Sandbox Code Playgroud)

有谁知道如何防止“无法加载pdf文档”??

pdf email-attachments node.js sendgrid

3
推荐指数
3
解决办法
2万
查看次数

标签 统计

email-attachments ×1

node.js ×1

pdf ×1

sendgrid ×1