2016-02-29 70 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