title: PDF file sent as email attachment becomes corrupted (java)
body: <p>I have a piece of code that attempts to send an email to a user and attach a pdf file. However, the attachment in the email received is always corrupted (simple files like txt files are fine). The original file is fine.</p>
  
  <pre><code>MultiPartEmail email = new MultiPartEmail();
  email.setHostName("mailhost.example.com");
  email.addTo("hello@example.com");
  email.setFrom("hi@example.com", "hi");
  email.setSubject("hello");
  email.setMsg("hello");
  File file = new File("file.pdf");
  email.attach(file);
  </code></pre>
  
  <p>I have also tried using <code>EmailAttachment</code> instead of just a <code>File</code>, like so:</p>
  
  <pre><code>EmailAttachment attachment = new EmailAttachment();
  attachment.setPath("path-to-file.pdf");
  attachment.setDisposition(EmailAttachment.ATTACHMENT);
  attachment.setName("file.pdf");
  email.attach(attachment);
  </code></pre>
  
  <p>In both cases, I receive an email with file.pdf attached, but when I open it, I get an error from Adobe Reader saying "There was an error opening this document. The file is damaged and could not be repaired." </p>
  
  <p>Does anyone know a fix for this?</p>