Jenkins on Windows - Could not connect to SMTP host, "Unrecognized SSL message"

2.9k views Asked by At

How do I enable STARTTLS for Jenkins running on Windows?

I have Jenkins running on a Windows 2008 server, and my email notifications are configured with the following info:

  • Host: smtp.office365.com
  • Port: 587
  • SMTP Auth: True
  • SSL: True
  • etc...

When I run a test, I get the following exception message:

javax.mail.MessagingException: Could not connect to SMTP host: smtp.office365.com, port: 587;
  nested exception is:
    javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

The issue seems to be due to smtp.office365.com using STARTTLS for the connection security. I have tried to enable STARTTLS through the jenkins.xml config file, by adding the following argument:

-Dmail.smtp.starttls.enable=true

  1. Is this correct switch/parameter?
  2. Is jenkins.xml the correct file to update?

Note: I am aware, some people have solved this in their Linux environment, but I am looking for a solution that's specific to Windows. Below is a snippet of my current jenkins.xml file:

<service>
  <id>jenkins</id>
  <name>Jenkins</name>
  <description>This service runs Jenkins continuous integration system.</description>
  <env name="JENKINS_HOME" value="%BASE%"/>

  <!--
    if you'd like to run Jenkins with a specific version of Java, specify a full path to java.exe.
    The following value assumes that you have java in your PATH.
  -->
  <executable>%BASE%\jre\bin\java</executable>
  <arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 -Dmail.smtp.starttls.enable=true</arguments>
  <!--
    interactive flag causes the empty black Java window to be displayed.
    I'm still debugging this.
  <interactive />
  -->
  <logmode>rotate</logmode>

  <onfailure action="restart" />
</service>
1

There are 1 answers

0
kaloyan On

I think the argument order DOES matter. I had to put the -Dmail.smtp.starttls.enable=true before the -jar argument.

-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -Dmail.smtp.starttls.enable=true -jar "%BASE%\jenkins.war" --httpPort=8080