title: java mail as pdf files as attachment
body: <p>I am trying to send an e-mail with a PDF as an attachment. It was including the file but its size was less than what it was on disk, and when trying to open it, it says the file is corrupted.</p>
  
  <pre><code>MimeBodyPart messageBodyPart = new MimeBodyPart();
          Multipart multipart = new MimeMultipart();
          messageBodyPart = new MimeBodyPart();
  
  
          try {
              messageBodyPart.attachFile(new File(filePath+"/"+fileName), "application/pdf", null);
  
              String message = "file attached. ";            
              messageBodyPart.setContent(message, "text/html");
              multipart.addBodyPart(messageBodyPart);
              mail.setMultiBody(multipart);
  </code></pre>