Jenkins – How to configure email notification in Jenkins

By | May 28, 2023

Jenkins is an open-source DevOps tool used for continuous integration and deployment via automation of the build, test, and deployment processes across different environments (DEV, SIT, UAT and PROD). Jenkins comes with a built-in feature to get notified once our CI/CD build gets completed. For this, we need to configure email notification in Jenkins server.

Steps to configure email notification in Jenkins

In order to configure email notification in Jenkins we first need to integrate Jenkins with GitHub. To learn more please refer Jenkins – How to integrate Jenkins with GitHub.

Step 1- Configurations

First, we need to configure the email to receive the build notifications. For this, log in to Jenkins > Dashboard > Manage Jenkins > Configure System.

configure email notification in Jenkins
Fig 1- Manage Jenkins Option

After we click on Manage Jenkins, a new window will appear where we are required to click on Configure System.

Jenkins System Configuration
Fig 2- System Configuration

On clicking Configure System, we need to scroll down to the bottom for the “Email Notification Section“, and we need to add the following email configurations:

How to configure email notification in Jenkins
Fig 3- E-mail Notification
Jenkins Test e-mail
Fig 4- E-mail Notification

In the above configurations, we have an email-password field from which we need to trigger the emails. If we directly enter the password of the e-mail address that we are using to trigger the mail, we will get an error: saying Application-specific password required. We can test it by adding the test configuration email address and clicking on Test configuration.

Application-specific password required error in Jenkins
Fig 5- Application-specific password error

Step 2- Generate Application-Specific Password

In order to resolve the above issue, we need to generate the application-specific password through google. Make sure that we have our 2-Step Verification done for our google account. First, we need to Login to our Gmail account > Manage your Google Account.

Manage your Google Account
Fig 6- Manage your Google Account

Once we click on Manage your Google Account, it opens our Google Account dashboard, where we need to go to Security > 2-Step Verification.

Jenkins 2-Step Verification
Fig 7- Google Account

On clicking 2-Step Verification, Google will ask for your e-mail password to login to your Google account.

Fig 8- Google Account Login

After we login, we will move to the 2-Step Verification page, where we need to scroll down and choose App Password.

App passwords for Jenkins
Fig 9- App Passwords

This will open a new window asking to setup the password for the app. Here, we need to select Others (custom name) from the drop-down menu.

How to generate App password for Jenkins
Fig 10- Select App

We need to provide a custom name for the app for which we are generating the password. Here, we are using Jenkins as the name of the app, and after that, we need to click on Generate.

Fig 11- Custom name for the App

This will generate a 16-digit password for our custom application.

Fig 12- 16-digit Password

We need to use this 16-digit password in the password field in Step 1 while System Configure. After adding this password, we can click on “Test Configuration to test whether our email is configured successfully. We can see a test email was received at the configured email.

Jenkins Test email
Fig 13- Test Email

Step 3- Output

In this step, we will push code to our source repository server, to which we have integrated our Jenkins server, and will push a failed build code to check whether we are receiving mail for unstable builds.

Sending e-mail using Jenkins build
Fig 14- Failed Build Logs

In the above picture, we can see Jenkins is sending email to the configured email ID.Now, we can also check that we have received the mail from Jenkins.

Jenkins build email notification
Fig 15- Jenkins Mail

One thought on “Jenkins – How to configure email notification in Jenkins

Leave a Reply

Your email address will not be published. Required fields are marked *