title: Node.js and Nodemailer: Can we attached PDF documents to emails?
body: <p>I am wanting to attach a PDF document using nodemailer and node.js, however, the only examples I am finding for attachments with nodemailer is with .txt files (<a href="https://stackoverflow.com/questions/21934667/how-to-attach-file-to-an-email-with-nodemailer">here</a>). </p>
  
  <p>Does anyone know if PDF document attachment is supported with nodemailer? </p>
  
  <p>Initially it appears a PDF can be attached, yet the PDF file that arrives through the email appears to be damaged (see image).</p>
  
  <p><a href="https://i.stack.imgur.com/NKSVS.png" rel="noreferrer"><img src="https://i.stack.imgur.com/NKSVS.png" alt="enter image description here"></a> </p>
  
  <p><strong>Code:</strong> (Adapted from Mahesh's answer)</p>
  
  <pre><code>fs.readFile('/filePath/fileName.pdf', function (err, data) {
  if (err) throw err;                                                  
  var mailOptions = {
      from: 'Test &lt;formEmail@gmail.com&gt;', // sender address                                   
      to: 'toPersonName &lt;toEmail@gmail.com&gt;', // list of receivers                                 
      subject: 'Attachment', // Subject line                                                 
      text: 'Hello world attachment test', // plaintext body                                                 
      html: '&lt;b&gt;Hello world attachment test HTML&lt;/b&gt;', // html body                                               
      attachments: [
          {
              filename: 'fileName.pdf',                                         
              contentType: 'application/pdf'
          }]
  };
  
  // send mail with defined transport object                                                 
  transporter.sendMail(mailOptions, function(error, info){
      if(error){
          return console.log(error);
      }
      console.log('Message sent: ' + info.response);
  });
  console.log(data);
  });
  </code></pre>
  
  <p><strong>Terminal Response:</strong></p>
  
  <pre><code>&lt;Buffer 25 50 44 46 2d 31 2e 33 0a 25 c4 e5 f2 e5 eb a7 f3 a0 d0 c4 c6 0a 34 20 30 20 6f 62 6a 0a 3c 3c 20 2f 4c 65 6e 67 74 68 20 35 20 30 20 52 20 2f 46 69 ... &gt;
  Message sent: 250 2.0.0 OK 1443026036 hq8sm3016566pad.35 - gsmtp
  </code></pre>