title: Jenkins SMTP TLS
body: <p>I'm trying to setup Jenkins to use our company's SMTP server to email build notifications. We are using TLS as the encryption method on port 587. I can not seem to get the email notification to work properly though.</p>
  
  <p>Here is my Hudson.Tasks.Mailer.xml file so you can see my config (I've removed the SMTP auth user and password and changed the smtpHost slightly just in case)</p>
  
  <pre><code>&lt;hudson.tasks.Mailer_-DescriptorImpl&gt;
    &lt;helpRedirect/&gt;
    &lt;defaultSuffix&gt;&lt;/defaultSuffix&gt;
    &lt;hudsonUrl&gt;http://localhost:8080/&lt;/hudsonUrl&gt;
    &lt;smtpAuthUsername&gt;&lt;/smtpAuthUsername&gt;
    &lt;smtpAuthPassword&gt;&lt;/smtpAuthPassw$
    &lt;adminAddress&gt;&lt;/adminAddress&gt;
    &lt;smtpHost&gt;pod#####.outlook.com&lt;/smtpHost&gt;
    &lt;useSsl&gt;true&lt;/useSsl&gt;
    &lt;smtpPort&gt;587&lt;/smtpPort&gt;
    &lt;charset&gt;UTF-8&lt;/charset&gt;
  &lt;/hudson.tasks.Mailer_-DescriptorImpl&gt;
  </code></pre>
  
  <p>It looks like this is a known issue, from <a href="http://issues.hudson-ci.org/browse/HUDSON-2206" rel="noreferrer">http://issues.hudson-ci.org/browse/HUDSON-2206</a></p>
  
  <p>I am not very familiar with Apple OS (which is the machine that is running Jenkins) but I thought I could resolve the issue using the workaround mentioned. I wasn't exactly sure where to put that workaround though, so I tried putting it here:
  /Library/Application Support/Jenkins/jenkins-runner.sh</p>
  
  <pre><code>defaults="defaults read /Library/Preferences/org.jenkins-ci"
  
  war=`$defaults war` || war="/Applications/Jenkins/jenkins.war"
  
  javaArgs="-Dmail.smtp.starttls.enable=\"true\""
  heapSize=`$defaults heapSize` &amp;&amp; javaArgs="$javaArgs -Xmx${heapSize}"
  permGen=`$defaults permGen` &amp;&amp; javaArgs="$javaArgs -XX:MaxPermSize=${permGen}"
  
  home=`$defaults JENKINS_HOME` &amp;&amp; export JENKINS_HOME="$home"
  
  add_to_args() {
    val=`$defaults $1` &amp;&amp; args="$args --${1}=${val}"
  }
  
  args=""
  add_to_args prefix
  add_to_args httpPort
  add_to_args httpListenAddress
  add_to_args httpsPort
  add_to_args httpsListenAddress
  add_to_args ajp13Port
  add_to_args ajp13ListenAddress
  
  echo "JENKINS_HOME=$JENKINS_HOME"
  echo "Jenkins command line for execution"
  echo /usr/bin/java $javaArgs -jar "$war" $args
  exec /usr/bin/java $javaArgs -jar "$war" $args
  </code></pre>
  
  <p>That didn't appear to resolve it. I can see that call in the console when Jenkins is started up, but when I try a test configuration email I get the following error:</p>
  
  <pre><code>Failed to send out e-mail
  
  javax.mail.MessagingException: Could not connect to SMTP host: pod#####.outlook.com, port: 587;
  nested exception is:
  javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
  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)
  </code></pre>
  
  <p>Any ideas on what else I can try? I've tried switching the email account to use gmail's smtp server and that works fine, but I'd rather have it using our smtp server if I can.</p>