title: Spring+JavaMail sending timeout
body: <p>I'm trying to send an email with Spring and JavaMail. Since I'm behind a proxy it probably shouldn't work, but I'd like to have a timeout because now javamail just hangs for who knows how long. </p>
  
  <p>This is my mailsender config in my spring xml:</p>
  
  <pre><code>&lt;bean id="gmailMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"&gt;
      &lt;property name="host"&gt;&lt;value&gt;smtp.gmail.com&lt;/value&gt;&lt;/property&gt;
      &lt;property name="port"&gt;&lt;value&gt;465&lt;/value&gt;&lt;/property&gt;
      &lt;property name="protocol"&gt;&lt;value&gt;smtp&lt;/value&gt;&lt;/property&gt;
      &lt;property name="username"&gt;&lt;value&gt;XXXXXX@gmail.com&lt;/value&gt;&lt;/property&gt;
      &lt;property name="password"&gt;&lt;value&gt;XXXXXXX&lt;/value&gt;&lt;/property&gt;
      &lt;property name="javaMailProperties"&gt;
          &lt;props&gt;
              &lt;prop key="mail.smtp.auth"&gt;true&lt;/prop&gt;
              &lt;prop key="mail.smtp.starttls.enable"&gt;true&lt;/prop&gt;
              &lt;prop key="mail.smtp.quitwait"&gt;false&lt;/prop&gt;
              &lt;prop key="mail.smtp.socketFactory.port"&gt;465&lt;/prop&gt;
              &lt;prop key="mail.smtp.socketFactory.class"&gt;javax.net.ssl.SSLSocketFactory&lt;/prop&gt;
              &lt;prop key="mail.smtp.socketFactory.fallback"&gt;false&lt;/prop&gt;
              &lt;prop key="mail.smtp.connectiontimeout"&gt;1000&lt;/prop&gt;
              &lt;prop key="mail.debug"&gt;true&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>When I send a mail I get the following debug output:</p>
  
  <pre><code>DEBUG: JavaMail version 1.5.4
  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,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
  DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
  DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
  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 "smtp.gmail.com", port 465, isSSL false
  </code></pre>
  
  <p>Then it hangs there. </p>
  
  <p>After like 5 minutes I get the:</p>
  
  <pre><code>javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
  </code></pre>
  
  <p>exception.</p>
  
  <p>Now I don't really want to know if it hangs because of proxy or firewall issues, I just want it to timeout after a short time if anything isnt working. Why isn't mail.smtp.connectiontimeout settings working properly? </p>