title: Jenkins Email Plugin : Could not connect to SMTP host: smtp.gmail.com, port: 465;
body: <p>I am trying to configure Email notifications for a Jenkins build job(Using the Mailer Plugin). I'm using Jenkins inside TomEE. When I tried to test my configuration, I got the javax.mail.MessagingException:</p>
  
  <pre><code>Failed to send out e-mail
  
  javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
  nested exception is:
  java.net.ConnectException: Connection timed out: connect
  
  at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
  
  at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
  
  at javax.mail.Service.connect(Service.java:317)
  
  at javax.mail.Service.connect(Service.java:176)
  
  at javax.mail.Service.connect(Service.java:125)
  
  at javax.mail.Transport.send0(Transport.java:194)
  
  at javax.mail.Transport.send(Transport.java:124)
  
  at hudson.tasks.Mailer$DescriptorImpl.doSendTestMail(Mailer.java:581)
  
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  
  at java.lang.reflect.Method.invoke(Method.java:498)
  
  at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:335)
  
  at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:175)
  
  at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:108)
  
  at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:124)
  
  at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
  
  at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
  
  at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
  
  at org.kohsuke.stapler.MetaClass$5.doDispatch(MetaClass.java:236)
  
  at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
  
  at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)
  
  at org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)
  
  at org.kohsuke.stapler.Stapler.invoke(Stapler.java:649)
  
  at org.kohsuke.stapler.Stapler.service(Stapler.java:238)
  
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
  
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  
  at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:135)
  
  at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:126)
  
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  
  at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:80)
  
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  
  at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:84)
  
  at hudson.security.UnwrapSecurityExceptionFilter.doFilter(UnwrapSecurityExceptionFilter.java:51)
  
  at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
  
  at jenkins.security.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:117)
  
  at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
  
  at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
  
  at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
  
  at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:142)
  
  at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
  
  at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
  
  at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
  
  at jenkins.security.BasicHeaderProcessor.doFilter(BasicHeaderProcessor.java:93)
  
  at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
  
  at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
  
  at hudson.security.HttpSessionContextIntegrationFilter2.doFilter(HttpSessionContextIntegrationFilter2.java:67)
  
  at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
  
  at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:76)
  
  at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:171)
  
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  
  at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:49)
  
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  
  at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:82)
  
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  
  at org.kohsuke.stapler.DiagnosticThreadNameFilter.doFilter(DiagnosticThreadNameFilter.java:30)
  
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
  
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
  
  at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
  
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:614)
  
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
  
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
  
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
  
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
  
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
  
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
  
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
  
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
  
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  
  at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>Caused by: java.net.ConnectException: Connection timed out: connect</p>
  
  <pre><code>at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
  
  at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
  
  at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
  
  at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
  
  at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
  
  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
  
  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
  
  at java.net.Socket.connect(Socket.java:589)
  
  at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
  
  at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:286)
  
  at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:205)
  
  at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
  
  ... 82 more
  </code></pre>
  
  <p>I read about the new security feature of Jenkins where it doesn't allow sending of mails to a non-Jenkins user. So I tried again by adding the following in my catalina.properties:</p>
  
  <pre><code>hudson.tasks.MailSender.SEND_TO_UNKNOWN_USERS=true
  hudson.tasks.MailSender.SEND_TO_USERS_WITHOUT_READ=true
  </code></pre>
  
  <p>I still got the same error.</p>
  
  <p>Any help would be great. Thanks.</p>