title: Javamail don't send emails with attachments
body: <p>I have an email session in Tomcat6: </p>
  
  <pre><code>&lt;Resource name="email" scope="Shareable" type="javax.mail.Session" mail.debug="true" mail.smtp.user="XXXX@gmail.com" mail.smtp.password="XXXX" mail.smtp.host="smtp.gmail.com" mail.smtp.port="465" mail.smtp.auth="true" mail.smtp.socketFactory.port="465" mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory" /&gt;
  </code></pre>
  
  <p>I send emails perfectly with this code:</p>
  
  <pre><code>javax.mail.Session sesion = getEmailSession();
  msg.setFrom(new InternetAddress("XXXX@gmail.com"));
  msg.setRecipients(new InternetAddress("XXXX@gmail.com"));
  msg.setSubject(MimeUtility.encodeText("About","iso-8859-1","Q"));
  
  Multipart mp = new MimeMultipart();
  
  MimeBodyPart mbp1 = new MimeBodyPart();
  MimeBodyPart mbp2 = new MimeBodyPart();
  
  mbp1.setText("Text","ISO-8859-15");
  
  FileDataSource fds = new FileDataSource("/opt/tmp/file.txt");           
  mbp2.setDataHandler(new DataHandler(fds));
  mbp2.setFileName(fds.getName());
  
  mp.addBodyPart(mbp1);
  mp.addBodyPart(mbp2);
  
  msg.setContent(mp);      
  msg.setSentDate(new Date());
  Transport.send(msg);
  </code></pre>
  
  <p>I works fine in all servers I have tried it (Windows and Linux), but in one server it doesn't work. The connection is closed abruptly.</p>
  
  <p>I have debugged the javamail communication and I have:</p>
  
  <pre><code>DEBUG: JavaMail version 1.4.5
  DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
  DEBUG: Tables of loaded providers
  DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
  DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
  DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
  DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
  DEBUG SMTP: useEhlo true, useAuth true
  DEBUG SMTP: useEhlo true, useAuth true
  DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
  220 smtp.gmail.com ESMTP w67sm3313556wmw.17 - gsmtp
  DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
  
  EHLO XXXX
  250-smtp.gmail.com at your service, [88.2.96.135]
  250-SIZE 35882577
  250-8BITMIME
  250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
  250-ENHANCEDSTATUSCODES
  250-PIPELINING
  250-CHUNKING
  250 SMTPUTF8
  DEBUG SMTP: Found extension "SIZE", arg "35882577"
  DEBUG SMTP: Found extension "8BITMIME", arg ""
  DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"
  DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
  DEBUG SMTP: Found extension "PIPELINING", arg ""
  DEBUG SMTP: Found extension "CHUNKING", arg ""
  DEBUG SMTP: Found extension "SMTPUTF8", arg ""
  DEBUG SMTP: Attempt to authenticate
  DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
  DEBUG SMTP: AUTH LOGIN command trace suppressed
  DEBUG SMTP: AUTH LOGIN succeeded
  DEBUG SMTP: use8bit false
  MAIL FROM:&lt;XXXX@gmail.com&gt;
  250 2.1.0 OK w67sm3313556wmw.17 - gsmtp
  RCPT TO:&lt;XXX@gmail.com&gt;
  250 2.1.5 OK w67sm3313556wmw.17 - gsmtp
  DEBUG SMTP: Verified Addresses
  DEBUG SMTP:   XXX@gmail.com
  DATA
  354  Go ahead w67sm3313556wmw.17 - gsmtp
  Date: Wed, 2 Dec 2015 14:49:44 +0100 (CET)
  From: XXX@gmail.com
  To: XXX@gmail.com
  Message-ID: &lt;17032702.26.1449064184719.JavaMail.root@Sage-Portal&gt;
  Subject: About
  MIME-Version: 1.0
  Content-Type: multipart/mixed; 
      boundary="----=_Part_25_13365288.1449064184718"
  
  ------=_Part_25_13365288.1449064184718
  Content-Type: text/plain; charset=ISO-8859-15
  Content-Transfer-Encoding: quoted-printable
  
  Text
  ------=_Part_25_13365288.1449064184718
  Content-Type: application/octet-stream; name=file.txt
  Content-Transfer-Encoding: 7bit
  Content-Disposition: attachment; filename=file.txt
  
  JAVAMAIL 1.4.5
  ------=_Part_25_13365288.1449064184718--
  .
  DEBUG SMTP: EOF: [EOF]
  DEBUG SMTP: got response code -1, with response: [EOF]
  RSET
  DEBUG SMTP: MessagingException while sending
  javax.mail.MessagingException: Can't send command to SMTP host;
    nested exception is:
      java.net.SocketException: Connection closed by remote host
      at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2163)
  </code></pre>
  
  <p>In this server sometimes the email with attachment is send, but normally not. If email has not attachments it always is send. In other servers the emails are always send.</p>
  
  <p>what can be the problem: Tomcat6, Gmail, Javamail, the server...</p>