Search code examples
jenkinsjenkins-pipelinejenkins-plugins

Emails sent by Jenkins Email Extension plugin not received?


pipeline 
{
  agent any
  stages
  {
    stage ('Start')
    {
      steps
      {
        echo 'Hello'
      }
    }
  }
  post
  {
    success
    {
      emailext (
          to: 'me@domain.zzz',
          subject: 'Test subject',
          body: 'Test body'
        )
    }
  }
}

This simple Jenkins pipeline seems to send email succesfully (output says: Sending email to: me@domain.zzz), but the emails are never received in the inbox.

There is nothing in the Jenkins log.
I can successfully send a test mail from Manage Jenkins -> Configure System -> E-mail Notification.
Here I am using Email Extension plugin. Is there a way to send a test mail from Email Extension plugin? Is there any other way to find out why the emails are not sent/received?


Solution

  • First: under Manage Jenkins -> Configure System -> E-mail Notification -> Advanced check Enable Debug Mode. This gives a lot of info after the job is run!

    The problem was that TLS was not enabled for Email Extension plugin since there is only an SSL checkbox available. When using classic Manage Jenkins -> Configure System -> E-mail Notification - there is a TLS checkbox, but not here.

    The solution to enable startTLS on Debian Linux: log into Jenkins and edit /etc/default/jenkins. Edit the JAVA_ARGS and add the following: "-Dmail.smtp.starttls.enable=true". Finally, this line for me looks like this: JAVA_ARGS="-Djava.awt.headless=true -Dmail.smtp.starttls.enable=true". Restart Jenkins: sudo service jenkins restart.

    After this is done, emailing works.