title: JavaMail SMTP Socket takes 1.5 min to Connect
body: <p>A web application (Tomcat6, Java6) on a cloud server (Linux, Debian Wheezy) is suddenly taking 1-2 minutes to connect to a remote SMTP to send out an email. </p>
  
  <p>I've logged into the server and confirmed I can ping and telnet into the SMTP server without any issues. The problem seems to be happening only when Java attempts the connection. </p>
  
  <pre class="lang-java prettyprint-override"><code>INFO  2015-01-12 16:17:58,872 [ajp-8009-10]
  DEBUG: setDebug: JavaMail version 1.5.2
  DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
  DEBUG SMTP: useEhlo true, useAuth true
  DEBUG SMTP: trying to connect to host "XXXXXXX", port XXX, isSSL false
  INFO  2015-01-12 16:19:32,753 [ajp-8009-11] ......
  220 XXXXXXXXX ESMTP
  DEBUG SMTP: connected to host "XXXXXXXX", port: XXX
  </code></pre>
  
  <p>You can see that the connection attempt begins at 16:17:58 and the connection is finally made at 16:19:32 - almost 1.5 minutes later. </p>
  
  <p>When I do the same from Telnet the response from the server is instant that's why it seems so strange that the app should take so long to connect. No other exceptions appear in the log files.</p>
  
  <p>I have contacted the company running the SMTP server as well as the cloud hosting provider to see if they have any suggestions. Any insight or approach to find the source of the problem is appreciated.</p>