title: Node.js SendGrid how to attach a PDF
body: <p>I'm using <a href="https://sendgrid.com/docs/Code_Examples/nodejs.html" rel="nofollow noreferrer">SendGrid</a> to send email in my Node.js application. Every combination I try to attach a pdf ends up with my attached pdf being unreadable.</p>
  <p>I've tried:</p>
  <pre><code>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'
  </code></pre>
  <p>does any one know how to prevent 'Failed to load pdf document'??</p>