Jenkins comes with a handy feature that enables us to send email notifications on different actions. To use this feature, we need to configure the email setting in Jenkins and some other settings in the email account.
Step 1. Configure the Email Notification in Jenkins
Go to the Manage Jenkins > Configure System then find Extended E-mail Notification and fill in the following details:
Note: Below details are for using a Gmail account for emails hence using Gmail SMTP server and port. If you are using a different email provider then please check the details form here.
✔ SMTP server – smtp.gmail.com
✔ SMTP Port – 465
Click on advanced below the SMTP Port box.
✔ SMTP Username – any Gmail id. This Gmail account will be used to send email notifications.
✔ SMTP Password – password of the Gmail id used above
✔ Check the Use SSL box.
✔ Default Recipient – Add a default email id.
Explore other options as well. But for now, we will leave the other option as it is.
Step 2. Allow less secure app for the Gmail used in the above step.
The E-mail Notification will work if we enable Less Secure App Access for the Gmail account.
Then go to the Security tab and Turn on Less secure app access.
Now the email notification will work without any errors.
Step 3. Test the configuration.
You can test the configuration by sending a demo email to the desired email id. Just go to the E-mail Notification fill in the same details in this section as above and at the bottom of the configuration section, there is an option to test the email notification.
Check the box and enter any email id on which you want to send an email.
We have learned how to configure email notifications in Jenkins. Now, we can use the email notification for different scenarios such as build failure, success, unstable, etc. We will see some examples in our next module.