2
我正在使用Meteor並試圖將pdf附加到電子郵件中。我現在將pdf作爲base64字符串返回給客戶端,並在新窗口中打開並顯示pdf。我想將base64作爲pdf格式的電子郵件附件。對於郵寄在Meteor中附加base64 PDF作爲電子郵件附件
服務器方法:
Meteor.methods({
sendEmail: function (to, from, subject, html,attachment) {
check([to, from, subject, html,attachment], [String]);
// Let other method calls from the same client start running,
// without waiting for the email sending to complete.
this.unblock();
Email.send({
to: to,
from: from,
subject: subject,
html: html,
attachment:attachment
});
}
});
片斷,返回的base64字符串,客戶端:
webshot(html_string, fileName, options, function(err) {
fs.readFile(fileName, function (err, data) {
if (err) {
return console.log(err);
}
fs.unlinkSync(fileName);
fut.return(data);
});
});
console.log("------------Waiting till PDF generated-----------");
pdfData = fut.wait();
base64String = new Buffer(pdfData).toString('base64');
console.log("------------Return result-----------");
return base64String;
客戶端代碼當前顯示的PDF:
Meteor.call('screenshot',html,style,function(err, res) {
if (err) {
console.error(err);
} else if (res) {
window.open("data:application/pdf;base64, " + res);//view PDF result
if(localbool===true) {
Meteor.call('sendEmail',
'[email protected]',//to
'[email protected]',//from
'Hello from Meteor!',//subject
'Sample HTML'//html
**What do I put here to attach base64 PDF**
);//close call for email send
alert("email sent!");
}
}
});
爲了將base64字符串附加爲pdf附件,我會做些什麼?我似乎無法得到與流星郵件發送的數據,因爲我得到錯誤「預期的字符串和對象」。
謝謝,