Jenkins can notify us about the status of each build via email. In this tutorial, we will test whether Jenkins Email Notification works and see how can we configure it.

Testing Email Notification

To check whether the Jenkins can send emails successfully, follow those steps:

First, we need to set the admin user who send us the emails and its email address. Go to to Manage Jenkins > Configure System. In the Configure System | Jenkins Location fill System Admin e-mail address. The format should be name <email-address> - for example Jenkins Daemon <admin@your-domain.com>.

In this tutorial, we will set it to Jenkins <admin@my-jenkins.com>.

Jenkins – Setting the admin user who send us the emails

Now, Go to Manage Jenkins > Configure System. In the Configure System | E-mail Notification

  • Check Test configuration by sending test e-mail checkbox
  • A Test e-mail recipient text box should appear.
  • Insert an email address to an account you can access.
  • Press Test Configuration.

Jenkins - Testing whether Jenkins can send emails successfully

Email was successfully sent appears, You should also check that you have received the email:

  • Login your the email account you specified above
  • Check if you have an email from admin you specified above in your inbox. (or your spam folder). The title of email should be something like ‘Test email #1’:

Jenkins – Test email

If you find this email , Jenkins was sent emails successfully. Otherwise, see how to configure your SMTP server below:

SMTP server on localhost

By default, Jenkins will send emails via the default SMTP server (which is normally the one running on localhost). If you do not have a SMTP server installed in your localhost. follow those steps:

  • The mailutils package offers SMTP server.

    root@jenkins:~# ssh my-jenkins
    login as: root
    Authenticating with public key "rsa-key_2016-08-01-jenkins"
    Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-34-generic x86_64)
    ...
    root@jenkins:~# apt-get install mailutils
    ...
    

Now, follow SMTP server settings:

SMTP server

Now, Go to Manage Jenkins > Configure System. In the Configure System | E-mail Notification and click Advanced button.

Enter your details of your SMTP server:

  • SMTP server is the domain of the machine. Leave empty for localhost
  • Check Use SMTP Authentication if the server requires authentication and then provide User Name and Password:
  • Check use SSL if server requires SSL connection.
  • Provide SMTP port if the port number for the mail server. Leave empty for the default one (25 for simple connection, 465 for SSL connection).

Jenkins – Setting SMTP Server

Now, test email notification again.