2016-02-29 69 views
1

我可以创建PDF文件,在Acrobat本地查看,通过电子邮件发送它使用流星电子邮件包,收到附件,但它是腐败的。 Acrobat无法打开它,并且实际上说“文件已损坏”,并且表明电子邮件解码可能是问题。流星电子邮件pdf附件与邮件

我试过“application/octet-stream”没有运气。有任何想法吗?

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

附件contentType设置为"application/pdf"

回答

0

有什么可以帮助的是作为附件的一部分传递'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: [email protected], 
     to: [email protected], 
     subject: 'mySubject', 
     attachments: [{'filename': 'myFileName 'contents': data}], 
     html: SSR.render(template, templateDataContext), 
    }); 
} 

我读文件和检验.pdf返回使用“fs.readFile”的数据,这是我插入到我的邮箱参数表。

+0

嗨Joos:你的解决方案效果很好。谢谢。我正在使用第三方工具来保存pdf。所以在第三方的回调中(文件保存成功后),我调用了readFile,并在readFile的回调函中发送了电子邮件。我不得不将这些回调包装在Meteor.bindEnvironment中以供它们使用。 – SudiB

+0

不错,很高兴听到! – Joos