Im using sendgrid to send email in my node.js application. Every combination I try to attach a pdf ends up with my attached pdf being unreadable.
i've tried:
fs.readFile('public_html/img/Report.pdf',function(err,data){
var base64data = new Buffer(data).toString('base64');
sendgrid.send({
to : hexDecode(_.e),
from : 'xxxxxxxxx@gmail.com',
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'
does any one know how to prevent 'Failed to load pdf document'??
Quite weird, I haven't really checked the docs and such because of answers beforehand already did but this was how I did mine and it worked.
hope this helps other people. using @sendgrid/mail": "^6.3.1",
According to the README, you should just pass your content, not turn it into a data URI.
With the latest version of the library, it goes like:
The field is called "attachments" now.(https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/mail/USE_CASES.md#attachments).