How to make Jenkins supports SMTP TLS on port 587


Jenkins supports the standard SMTP on port 25 and SSL (for Gmail, the port is 495). But looks like it doesn't support the TLS encrypted way on port 587.

I searched a lot on Google, especially the Jenkins forums, but got nothing. Then I found something about Java, looks like JVM also doesn't support TLS by default, but we can add a parameter Dmail.smtp.starttls.enable="true" to enable it.
Because Jenkins uses JVM, so I thought maybe this was the root cause.

So I added the parameter Dmail.smtp.starttls.enable="true" into the option "JENKINS_JAVA_OPTIONS" of /etc/sysconfig/jenkins.

After this, restart Jenkins.
# /etc/init.d/jenkins restart

Then configure it again, cancel the "Use SSL", choose the "Test configuration by sending test e-mail" to test.

, ,

  1. #1 by Andy Steady on November 6, 2012 - 12:14 am

    Nice one - that solves my problem.
    For reference you can find the relevant file here /etc/default/jenkins on ubuntu.
    I added following lines, not sure which one did the trick

    JAVA_ARGS="-Dmail.smtp.starttls.enable=true"
    JENKINS_JAVA_OPTIONS="-Dmail.smtp.starttls.enable=true"

    • #2 by mcsrainbow on November 6, 2012 - 3:23 pm

      Glad to hear that this article helped you on this problem.
      I think Jenkins uses the JENKINS_JAVA_OPTIONS by default, you can test it.

  2. #3 by Andy Steady on November 7, 2012 - 4:47 am

    yes.
    I forgot to mention - actually I used this solution to get the integration between jenkins and office365 going for snmp build notifications.
    Adding these key words might help a few google searches - there wasn't much out there!

    thanks again :)

    • #4 by mcsrainbow on November 7, 2012 - 9:46 am

      Nice.

      • #5 by Ricard Marí on December 20, 2012 - 6:37 pm

        Hi,

        I am trying to configure Jenkins with an account of Office365. I added the next line in /etc/default/jenkins

        JENKINS_JAVA_OPTIONS="-Dmail.smtp.starttls.enable=true"

        But, when I test configuration it doesn't work. Can you help me? Thanks. I send you the error message:

        Failed to send out e-mail

        javax.mail.AuthenticationFailedException: No authentication mechansims supported by both server and client

        • #6 by Jason Swager on November 10, 2013 - 1:51 pm

          I have the same problem: No authentication mechansims supported by both server and client.

          Did you find a solution to this?

          • #7 by mcsrainbow on November 12, 2013 - 9:17 pm

            Did you try this?:
            Then configure it again, cancel the "Use SSL", choose the "Test configuration by sending test e-mail" to test.

      • #8 by Srikanth on January 29, 2016 - 9:32 pm

        Hi,
        I am trying to integrate Jenkins with office365 and as mentioned above, (please correct me if i am wrong) i am using windows & adding the mentioned params in jenkins.xml file. I get a message as 'please check if this file is opened in another program'. I have opened it using notepad++. And also what will be the syntax to add the two lines? Please help...

  3. #9 by shreyas on November 25, 2013 - 6:48 pm

    I tried that -
    in the file jenkins , I added the following line-
    JAVA_ARGS="-Dmail.smtp.starttls.enable=true"
    JENKINS_JAVA_OPTIONS="-Dmail.smtp.starttls.enable=true"

    I disabled this line -
    #JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"

    Now, after restarting the jenkins service. I get the following error.

    The smtp server = smtp.office365.com
    Use SMTP Authentication is checked.
    Use SSL is unchecked.
    SSL Port is 587/ tried with empty also.

    On test configuration it fails. Please help me.
    Failed to send out e-mail

    com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.1 Client does not have permissions to send as this sender

    • #10 by Vishal on July 16, 2014 - 1:26 pm

      shreyas :
      I tried that -
      in the file jenkins , I added the following line-
      JAVA_ARGS="-Dmail.smtp.starttls.enable=true"
      JENKINS_JAVA_OPTIONS="-Dmail.smtp.starttls.enable=true"
      I disabled this line -
      #JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"
      Now, after restarting the jenkins service. I get the following error.
      The smtp server = smtp.office365.com
      Use SMTP Authentication is checked.
      Use SSL is unchecked.
      SSL Port is 587/ tried with empty also.
      On test configuration it fails. Please help me.
      Failed to send out e-mail
      com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.1 Client does not have permissions to send as this sender
      ...

      I am also facing same problem can you please tell me how you fix this. Thanks

  4. #11 by Prakash Bhagat on February 11, 2014 - 3:04 pm

    Please specify JAVA_ARGS="-Dmail.smtp.starttls.enable=true" as mentioned in the forum.

    Make sure admin email should be same as the username provided.

    It works in my case.

    Thanks for your support

  5. #12 by Luan Nguyen on January 7, 2016 - 1:39 am

    Vishal :

    shreyas :
    I tried that -
    in the file jenkins , I added the following line-
    JAVA_ARGS="-Dmail.smtp.starttls.enable=true"
    JENKINS_JAVA_OPTIONS="-Dmail.smtp.starttls.enable=true"
    I disabled this line -
    #JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"
    Now, after restarting the jenkins service. I get the following error.
    The smtp server = smtp.office365.com
    Use SMTP Authentication is checked.
    Use SSL is unchecked.
    SSL Port is 587/ tried with empty also.
    On test configuration it fails. Please help me.
    Failed to send out e-mail
    com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.1 Client does not have permissions to send as this sender
    ...

    I am also facing same problem can you please tell me how you fix this. Thanks

    Also need to set the sender as the User Name:
    Manage Jenkins -> Configure System -> Jenkins Location -> System Admin e-mail address

    FYI - http://stackoverflow.com/questions/9693526/how-can-i-set-the-senders-address-in-jenkins

  6. #13 by Srikanth on January 29, 2016 - 9:30 pm

    Hi,
    I am trying to integrate Jenkins with office365 and as mentioned above, (please correct me if i am wrong) i am using windows & adding the mentioned params in jenkins.xml file. I get a message as 'please check if this file is opened in another program'. I have opened it using notepad++. And also what will be the syntax to add the two lines? Please help...

  7. #14 by uday on June 2, 2017 - 5:12 pm

    How to do the above settings for windows 7 machine and jenkins hosted on tomcat installed on the same machine??

(will not be published)

*


Fork me on GitHub