title: javamail 1.5 socket read timeout exception
body: <p>I am working on an application which must send emails. I use javamail 1.5. And after deploying it in client machine they get error and send me logs like this:</p>
  
  <pre><code>DEBUG: JavaMail version 1.5.1
  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-a.cm.es", port 25, isSSL false
  DEBUG SMTP: exception reading response, THROW: 
  java.net.SocketTimeoutException: Read timed out
      at java.net.SocketInputStream.socketRead0(Native Method)
      at java.net.SocketInputStream.read(SocketInputStream.java:152)
      at java.net.SocketInputStream.read(SocketInputStream.java:122)
      at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:124)
      at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
      at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:89)
      at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2207)
      at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1962)
      at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:656)
      at javax.mail.Service.connect(Service.java:345)
      at javax.mail.Service.connect(Service.java:226)
      at javax.mail.Service.connect(Service.java:246)
      at es.redfinanciera.lq.action.ExpedienteActionLS.mandarCorreo(ExpedienteActionLS.java:2560)
      at es.redfinanciera.lq.action.ExpedienteActionLS.pedirDoc(ExpedienteActionLS.java:2362)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:891)
      at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1293)
      at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
      at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:117)
      at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:108)
      at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1369)
      at ognl.ASTMethod.getValueBody(ASTMethod.java:90)
      at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
      at ognl.SimpleNode.getValue(SimpleNode.java:258)
      at ognl.Ognl.getValue(Ognl.java:494)
      at ognl.Ognl.getValue(Ognl.java:458)
      at com.opensymphony.xwork2.ognl.OgnlUtil$2.execute(OgnlUtil.java:309)
      at com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecute(OgnlUtil.java:340)
      at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:307)
      at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:423)
      at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:287)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:250)
      at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:41)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167)
      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
      at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:76)
      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:125)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:326)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:139)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
      at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
      at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:564)
      at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
      at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
      at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
      at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
      at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3436)
      at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402)
      at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
      at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
      at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
      at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285)
      at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201)
      at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
      at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572)
      at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255)
      at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
      at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)
  </code></pre>
  
  <p>I cannot get access to their machine, and all test in local runs fine. I tried to send email using the smtp server as mentioned in log, but I cannot get access and maybe it is because I am in my developing machine not in theirs. And connecting from my local machine I get following exception:</p>
  
  <pre><code>    Mensaje: Couldn't connect to host, port: smtp-a.cm.es, 25; timeout 5000
  com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp-a.cm.es, 25; timeout 5000;
    nested exception is:
      java.net.UnknownHostException: smtp-a.cm.es
      at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1984)
      at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:656)
      at javax.mail.Service.connect(Service.java:345)
      at javax.mail.Service.connect(Service.java:226)
      at javax.mail.Service.connect(Service.java:246)
      at es.redfinanciera.lq.action.ExpedienteActionLS.mandarCorreo(ExpedienteActionLS.java:3182)
      at es.redfinanciera.lq.action.ExpedienteActionLS.pedirDoc(ExpedienteActionLS.java:2981)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:870)
      at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1293)
      at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
      at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:117)
      at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:108)
      at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1369)
      at ognl.ASTMethod.getValueBody(ASTMethod.java:90)
      at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
      at ognl.SimpleNode.getValue(SimpleNode.java:258)
      at ognl.Ognl.getValue(Ognl.java:494)
      at ognl.Ognl.getValue(Ognl.java:458)
      at com.opensymphony.xwork2.ognl.OgnlUtil$2.execute(OgnlUtil.java:309)
      at ......
  
      (first part not complete coz characters numbers limit)
  
  Caused by: java.net.UnknownHostException: smtp-a.cm.es
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
      at java.net.Socket.connect(Socket.java:579)
      at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:299)
      at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:229)
      at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1950)
      ... 131 more
  </code></pre>
  
  <p>They are similar but not the same. In local I cannot connect, but in client the app is connected but cannot read response. Can someone help?? Thanks!!!</p>
  
  <p>I can provide my mail sender connection part details here:</p>
  
  <pre><code>input = MailSmtpSender.class.getResourceAsStream("/config/properties/mail.properties");
          prop = new Properties();
          prop.load(input);
          prop.setProperty("mail.smtp.connectiontimeout", "5000");
          prop.setProperty("mail.smtp.timeout", "5000");
          prop.put("mail.smtp.starttls.enable", "true");
          prop.put("mail.debug", "true");
          Session session = Session.getInstance(prop);
          MimeMessage message = new MimeMessage(session);
          ....(build message)
          Transport t = session.getTransport(prop.getProperty("mail.smtp.protocol"));
          try {
              t.connect(prop.getProperty("mail.smtp.user"), prop.getProperty("mail.smtp.pass"));
              t.sendMessage(message, message.getAllRecipients());
          } catch (Exception e) {
              ...
          } finally {
              t.close();
          }
  </code></pre>
  
  <p>mail.properties:(snippet)</p>
  
  <pre><code>mail.smtp.starttls.enable=true
  mail.smtp.protocol=smtp
  mail.smtp.useTSL=false
  mail.smtp.auth=false
  mail.smtp.port=25
  mail.smtp.host=smtp-a.cm.es  //this is what client need. I test locally with other servers and works fine.
  </code></pre>