带 mailgun 的 Meteor Email pdf 附件

Meteor Email pdf attachment with mailgun

我可以创建 pdf 文件,在本地的 Acrobat 中查看,使用 Meteor 的电子邮件包通过电子邮件发送,接收附件但它已损坏。 Acrobat 无法打开它,实际上说 "file is damaged" 并建议电子邮件附件解码可能是问题所在。

我尝试了 "application/octet-stream",但没有成功。有什么想法吗?

Email.send({
               to: "bhattacharya.sudi@gmail.com",
               from: from,
               subject: fn.alertTypeLabel + ' ' + p[0].parameterLabel,
               html: SSR.render( template, templateDataContext ),
               attachments : [ { fileName : fileName, filePath : filesPath, contentType : contentType } ]
                            });

附件内容类型设置为 "application/pdf"

将 'contents' 参数作为附件的一部分传递可能会有帮助。

在我自己的项目中,我是这样做的:

var fs = Meteor.npmRequire('fs');
var myPath = "assets/app/test.pdf"; // this should be wherever you store your pdf
fs.readFile(myPath, function (err, data) {
    if (err) {
        throw err;
    }

    Email.send({
        from: test@gmail.com,
        to: otherTest@gmail.com,
        subject: 'mySubject',
        attachments: [{'filename': 'myFileName 'contents': data}],
        html:  SSR.render( template, templateDataContext ),
    });
}

我使用 'fs.readFile' 读取文件 test.pdf 和 return 其数据,并将其插入到我的电子邮件参数列表中。