【问题标题】:Meteor Email pdf attachment with mailgunMeteor Email pdf 附件与 mailgun
【发布时间】:2016-06-12 19:46:45
【问题描述】:

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

我尝试了“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"

【问题讨论】:

    标签: pdf meteor email-attachments mailgun


    【解决方案1】:

    将 '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 ),
        });
    }
    

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

    【讨论】:

    • 嗨 Joos:您的解决方案效果很好。谢谢你。我正在使用第三方工具来保存 pdf。所以在第三方的回调中(文件保存成功后)我正在调用 readFile 并且在 readFile 的回调中我正在发送电子邮件。我必须将回调包装在 Meteor.bindEnvironment 中才能正常工作。
    猜你喜欢
    • 2021-06-02
    • 2023-03-21
    • 2020-07-15
    • 1970-01-01
    • 1970-01-01
    • 2022-12-27
    • 1970-01-01
    • 2014-12-20
    • 2012-12-23
    相关资源
    最近更新 更多