title: Java mail attachment not working on Tomcat
body: <p>I have an application which e-mails confirmations. The email part utilises Commons Mail API. The simple code which does the send mail is as shown below;</p>
  
  <pre><code>import org.apache.commons.mail.*;
  ...
  // Create the attachment
  EmailAttachment attachment = new EmailAttachment();
  attachment.setURL(new URL("http://cashew.org/doc.pdf"));
  attachment.setDisposition(EmailAttachment.ATTACHMENT);
  attachment.setDescription("Testing attach");
  attachment.setName("doc.pdf");
  
  // Create the email message
  MultiPartEmail email = new MultiPartEmail();
  email.setHostName("mail.cashew.com");
  email.addTo("ben@cashew.org");
  email.setFrom("lot@cashew.org");
  email.setSubject("Testing);
  email.setMsg("testing message");
  
  // add the attachment
  email.attach(attachment);
  
  // send the email
  email.send();
  </code></pre>
  
  <p>My problem is, when I execute this application from Eclipse, I get email sent with attachment without any issues. But when i deploy the application to Tomcat server (I have </p>
  
  <p>tried both version 5 &amp; 6 no joy), the e-mail is sent with below content;</p>
  
  <pre><code>------=_Part_0_25002283.1275298567928
  Content-Type: text/plain; charset=us-ascii
  Content-Transfer-Encoding: 7bit
  
  testing
  
  
  Regards,
  
  los
  
  ------=_Part_0_25002283.1275298567928
  Content-Type: application/pdf; name="doc.pdf"
  Content-Transfer-Encoding: base64
  Content-Disposition: attachment; 
   filename="doc.pdf"
  Content-Description: Testing attach
  
  JVBERi0xLjQNJeLjz9MNCjYzIDAgb2JqDTw8L0xpbmVhcml6ZWQgMS9MIDMxMzE4Mi9PIDY1L0Ug
  Mjg2NjY5L04gMS9UIDMxMTgwMi9IIFsgMjgzNiAzNzZdPj4NZW5kb2JqDSAgICAgICAgICAgICAg
  DQp4cmVmDQo2MyAxMjcNCjAwMDAwMDAwMTYgMDAwMDAgbg0KMDAwMDAwMzM4MCAwMDAwMCBuDQow
  MDAwMDAzNTIzIDAwMDAwIG4NCjAwMDAwMDQzMDcgMDAwMDAgbg0KMDAwMDAwNTEwOSAwMDAwMCBu
  DQowMDAwMDA2Mjc5IDAwMDAwIG4NCjAwMDAwMDY0MTAgMDAwMDAgbg0KMDAwMDAwNjU0NiAwMDAw
  MCBuDQowMDAwMDA3OTY3IDAwMDAwIG4NCjAwMDAwMDkwMjMgMDAwMDAgbg0KMDAwMDAwOTk0OSAw
  MDAwMCBuDQowMDAwMDExMDAwIDAwMDAwIG4NCjAwMDAwMTIwNTkgMDAwMDAgbg0KMDAwMDAxMjky
  MCAwMDAwMCBuDQowMDAwMDEyOTU0IDAwMDAwIG4NCjAwMDAwMTI5ODIgMDAwMDAgbg0KMDAwMDAx
  .......
  CnN0YXJ0eHJlZg0KMTE2DQolJUVPRg0K
  ------=_Part_0_25002283.1275298567928--
  </code></pre>
  
  <p>One thing also I have noticed is, the header information donot show TO and Subject values. Hmm pretty wierd. 
  I have to point out that, above is not generated of DEBUG, it is the actual message recieved in my outlook client.</p>
  
  <p>Can someone help me please!</p>
  
  <p><strong>Update</strong>: The application is pretty simple. Attachment a Part and text message as a seperate part also.    </p>
  
  <pre><code>   public final void Email(String from, String to, String cc,
            String subject, String message, String doc, String bcc) {
  
        MultiPartEmail email = new MultiPartEmail();
  
      try {
  
          if (!(doc == null)) {
                       EmailAttachment attachment = new EmailAttachment();
                       attachment.setURL(new URL("http://cashew.org/doc.pdf"));
           attachment.setDisposition(EmailAttachment.ATTACHMENT);
           attachment.setDescription("Testing attach");
           attachment.setName("doc.pdf");
                       email.attach(attachment);  
          }
  
  
          email.setHostName("mail.cashew.com");
  
          // [ Set Header details
          email.setTo(getAddress(to));
          email.setFrom(from);
          email.setSubject(subject);
  
  
          if (!(cc == null)) {
                eEmail.setCc(getAddress(cc));
          }
  
          if (!(bcc == null)) {
              email.setBcc(getAddress(bcc));
          }
  
          email.setMsg(message);
  
          email.send();
  
  
      } catch (Exception ex) {
          ex.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Do anyone knows what's going on? </p>