我在用着SendGrid在我的 Node.js 应用程序中发送电子邮件。我尝试附加 pdf 的每个组合最终都会导致我附加的 pdf 无法读取。
我试过了:
fs.readFile('public_html/img/Report.pdf',function(err,data){
var base64data = new Buffer(data).toString('base64');
sendgrid.send({
to : hexDecode(_.e),
from : '[email protected]',
subject : 'Report',
files : [{filename:'Report.pdf',content:'data:application/pdf;base64,'+base64data}],
// files : [{filename:'Report.pdf',contentType:'data:application/pdf',url:'public_html/img/'Report.pdf'}],
// files : [{filename:'Report.pdf',url:'public_html/img/'Report.pdf'}],
html : 'bla bla'
有谁知道如何防止“无法加载 pdf 文档”?
使用最新版本的库,它是这样的:
fs.readFile('public_html/img/Report.pdf', function(err, data) {
sendgrid.send({
to : hexDecode(_.e),
from : '[email protected]',
subject : 'Report',
attachments : [{filename: 'Report.pdf',
content: data,
type: 'application/pdf',
disposition: 'attachment',
contentId: 'myId'
}],
html : 'bla bla'
该字段现在称为“附件”。(https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/mail/USE_CASES.md#attachments).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)