Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-58813

Cannot send Email notification over office365 smtp with starttls has no effect

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • mailer-plugin
    • None
    • Jenkins ver. 2.187, Ubuntu 18.04

      I migrated our Jenkins server from an Ubuntu 16.04 VPS to another 18.04. I installed Jenkins via apt on the new server first and then rsync all the files and config from the old one. Everything looks working fine.

      But, email notifications not.

      •  SMTP server : smtp.office365.com
      • Use SMTP Authentication : checked
        • "User name" match with the "System Admin e-mail address"
      • Use SSL : unchecked
      • SMTP Port : 587

      I modified the "/etc/default/jenkins" file, added line

      • JAVA_ARGS="-Djava.awt.headless=true -Dmail.smtp.starttls.enable=true"

      But when I try to run "Test configuration" I got the given error message below:

      "Failed to send out e-mail"

      StackTrace

      java.net.SocketException: Connection closed by remote host
      	at sun.security.ssl.SSLSocketImpl.checkWrite(SSLSocketImpl.java:1547)
      	at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:71)
      	at com.sun.mail.util.TraceOutputStream.write(TraceOutputStream.java:114)
      	at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
      	at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
      	at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2104)
      Caused: 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:2106)
      	at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2093)
      	at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:1184)
      	at javax.mail.Transport.send0(Transport.java:197)
      	at javax.mail.Transport.send(Transport.java:124)
      	at hudson.tasks.Mailer$DescriptorImpl.doSendTestMail(Mailer.java:613)
      	at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
      	at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:396)
      	at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:408)
      	at org.kohsuke.stapler.interceptor.RequirePOST$Processor.invoke(RequirePOST.java:77)
      	at org.kohsuke.stapler.PreInvokeInterceptedFunction.invoke(PreInvokeInterceptedFunction.java:26)
      	at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:212)
      	at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:145)
      	at org.kohsuke.stapler.MetaClass$11.doDispatch(MetaClass.java:535)
      	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
      	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:747)
      	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:878)
      	at org.kohsuke.stapler.MetaClass$4.doDispatch(MetaClass.java:280)
      	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
      	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:747)
      	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:878)
      	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:676)
      	at org.kohsuke.stapler.Stapler.service(Stapler.java:238)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
      	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:873)
      	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1623)
      	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:154)
      	at org.jenkinsci.plugins.ssegateway.Endpoint$SSEListenChannelFilter.doFilter(Endpoint.java:243)
      	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:151)
      	at io.jenkins.blueocean.ResourceCacheControl.doFilter(ResourceCacheControl.java:134)
      	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:151)
      	at io.jenkins.blueocean.auth.jwt.impl.JwtAuthenticationFilter.doFilter(JwtAuthenticationFilter.java:61)
      	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:151)
      	at hudson.plugins.locale.LocaleFilter.doFilter(LocaleFilter.java:42)
      	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:151)
      	at hudson.plugins.greenballs.GreenBallFilter.doFilter(GreenBallFilter.java:59)
      	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:151)
      	at jenkins.telemetry.impl.UserLanguages$AcceptLanguageFilter.doFilter(UserLanguages.java:128)
      	at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:151)
      	at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:157)
      	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
      	at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:99)
      	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
      	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:90)
      	at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:171)
      	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
      	at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:49)
      	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
      	at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:82)
      	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
      	at org.kohsuke.stapler.DiagnosticThreadNameFilter.doFilter(DiagnosticThreadNameFilter.java:30)
      	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
      	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:540)
      	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
      	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
      	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
      	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1700)
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
      	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
      	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)
      	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1667)
      	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
      	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
      	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
      	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
      	at org.eclipse.jetty.server.Server.handle(Server.java:505)
      	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)
      	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)
      	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
      	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
      	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
      	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
      	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:698)
      	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:804)
      	at java.lang.Thread.run(Thread.java:748)
      

      What I tried to do too:

      • Restart Jenkins multiple times (Through GUI and from command line as well)
      • Add line "JENKINS_JAVA_OPTIONS="-Dmail.smtp.starttls.enable=true"" to "/etc/default/jenkins"
      • Under Script Console run command "System.setProperty("mail.smtp.starttls.enable","true")"
      • Try enable and disable SSL and change port 467

       

      So, the settings under the E-mail notification section are all the same as on the old server with Jenkins version 2.176.2. For me it looks like the "-Dmail.smtp.starttls.enable=true" has no effect or maybe this line looks interesting for me at the stack trace "at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:99)".

      What could cause the problem?

       

       

          [JENKINS-58813] Cannot send Email notification over office365 smtp with starttls has no effect

          Somehow I got the emails to my inbox now.  I restarted Jenkins and both the host machine several times and updated Jenkins version too. But when I test email configuration by 'Test configuration by sending test e-mail' from Manage Jenkins > Configure System > E-mail notification section. I've got the following error below:

          javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful [AM0PR0202CA0008.eurprd02.prod.outlook.com]
          
          	at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:809)
          	at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:752)
          	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:669)
          	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:671)
          	at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
          	at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:396)
          	at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:408)
          	at org.kohsuke.stapler.interceptor.RequirePOST$Processor.invoke(RequirePOST.java:77)
          	at org.kohsuke.stapler.PreInvokeInterceptedFunction.invoke(PreInvokeInterceptedFunction.java:26)
          	at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:212)
          	at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:145)
          	at org.kohsuke.stapler.MetaClass$11.doDispatch(MetaClass.java:535)
          	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
          ...

          My thought was about why the emails arrive despite test fails it's because I use the 'Extended E-mail Notification' plugin in my Jobs but the 'E-mail notification' still looks like not working.

          Krisztián Gyula Tóth added a comment - Somehow I got the emails to my inbox now.  I restarted Jenkins and both the host machine several times and updated Jenkins version too. But when I test email configuration by 'Test configuration by sending test e-mail' from Manage Jenkins > Configure System > E-mail notification section. I've got the following error below: javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful [AM0PR0202CA0008.eurprd02.prod.outlook.com] at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:809) at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:752) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:669) 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:671) at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627) at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:396) at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:408) at org.kohsuke.stapler.interceptor.RequirePOST$Processor.invoke(RequirePOST.java:77) at org.kohsuke.stapler.PreInvokeInterceptedFunction.invoke(PreInvokeInterceptedFunction.java:26) at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:212) at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:145) at org.kohsuke.stapler.MetaClass$11.doDispatch(MetaClass.java:535) at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58) ... My thought was about why the emails arrive despite test fails it's because I use the 'Extended E-mail Notification' plugin in my Jobs but the 'E-mail notification' still looks like not working.

          Paul Morahan added a comment -

          I had exactly the same problem with the same stack trace, same Jenkins version, and same configuration steps, and it required two things to fix it:

          1) upgrading the Mailer plugin from v1.24 to v1.28

          2) the sysadmin email address MUST match the sending SMTP user. I tried making it another valid user on the same domain, but that didn't work. A lot of people online say that it just needs to be another valid account, but from what I could see, it didn't work until they matched. So now I have a 'noreply' user as the system admin's email address in Jenkins

          Paul Morahan added a comment - I had exactly the same problem with the same stack trace, same Jenkins version, and same configuration steps, and it required two things to fix it: 1) upgrading the Mailer plugin from v1.24 to v1.28 2) the sysadmin email address MUST match the sending SMTP user. I tried making it another valid user on the same domain, but that didn't work. A lot of people online say that it just needs to be another valid account, but from what I could see, it didn't work until they matched. So now I have a 'noreply' user as the system admin's email address in Jenkins

          Tommy Sparber added a comment -

          This should be fixed with the PR 67 once it is approved, merged and released.

          Tommy Sparber added a comment - This should be fixed with the PR 67 once it is approved, merged and released.

          Guy Mesika added a comment -

          Has the same issue exactly

          upgrade the mailer plugin to 1.29

          Guy Mesika added a comment - Has the same issue exactly upgrade the mailer plugin to  1.29

          Rakesh S added a comment - - edited

          hi gmesika/alecharp,

          I am working on windows 7 machine, i have configured below but still getting the same error 

          1. extended email notification with smtp.office365.com, unchecked SSl, Port 587
          2. upgraded mailer plug in to 1.29 
          3. added -Dmail.smtp.starttls.enable=true to JAVA_HOME arguments in jenkins.xml file 

          When I am checking "Test configuration by sending test e-mail" getting error message as "javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful [BMXPR01CA0071.INDPRD01.PROD.OUTLOOK.COM]"

          Attached the screenshots. Could you please help.

           

          Thanks,

          Rakesh

          Rakesh S added a comment - - edited hi gmesika / alecharp , I am working on windows 7 machine, i have configured below but still getting the same error  extended email notification with smtp.office365.com, unchecked SSl, Port 587 upgraded mailer plug in to 1.29  added -Dmail.smtp.starttls.enable=true to JAVA_HOME arguments in jenkins.xml file  When I am checking "Test configuration by sending test e-mail" getting error message as "javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful [BMXPR01CA0071.INDPRD01.PROD.OUTLOOK.COM] " Attached the screenshots. Could you please help.   Thanks, Rakesh

            alecharp Adrien Lecharpentier
            tkrisztiangyula Krisztián Gyula Tóth
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: