How to Install and Configure Email Notifications in Jenkins

 In All Tutorials
Last Updated On September 18, 2019

Jenkins is an open source tool used to perform Continuous Integration (CI) and Continuous Development (CD) by automating build/test/deployments. Using Jenkins you can easily automate the complete process of build to deploy across different environments (Dev/SIT/UAT/Production) by creating different jobs or pipeline.

When you create these jobs there must be some way to get the team and yourself notified about the build/test/deploy status.This is where Email Notifications can be used. Jenkins provide plugins to Send Emails.You just need to install and configure the plugin correctly.

This tutorial will help you setting up the email notifications in few simple steps 🙂

You can configure email notifications in your jobs in two ways:
1) Default Email Notifier (Email-Notification)
2) Extended Email Notification (Editable E-mail Notification)

In Extended Email Notifications you can set triggers (e.g. build is unstable or before build), specify email subject, content and recipients.

Prerequisites to Install and Configure Email Notification in Jenkins

This tutorial is based on Jenkins version 2.194 installed on localhost and using http port 8071.

Step 1 - Installing Email Extension Plugin.

  1. Open Jenkins using the following URL: http://localhost:8080/ on any browser (in this tutorial port 8071 is used).

  2. Click on Manage Jenkins.

    manage jenkins_img

  3. Click on Manage Plugins.

    manage_plugins_img

  4. Select Email Extension and Email Extension Template Plugin and click Install Without Restart.

    installation_img

Once the plugin is installed let's configure it with SMTP servers so that Jenkin emails can be routed via these SMTP servers.

configure_img

Step 2 - Configure Email Notifications

  1. Click on Manage Jenkins and then Configure system

    configure_system_img

  2. Scroll below till E-mail Notification and click on advanced. Setup up as shown in below screenshot and save it.

    configure_system_img

You can test configurations by entering recipient email address and clicking on test configuration. If all is good it will show a message - Email sent successfully. You may get error while testing configurations, below is possible errors and solution to it.

test_configuration_img

In step 4 you will see the steps to configure email content and set triggers using Extended Email Notification.

Step 3 — Configuring Email-Notification in our jobs or pipeline

  1. Go to your Jenkins home page and click on the created job (Here its gradlerun)

    configure_email_notification

2) Click on Manage Plugins

manage_plugins

3) Once your job configuration opens, scroll down to add post-build action and select Email Notifications.

configure_jekins_job

4) Enter recipients and check Send Email for every unstable build and save it.

configure_jekins_job

Here you go! Run your job and you start receiving emails.

Optional Steps

Step 4 - Configure Extended Email Notification

From step 2, scroll below till Extended E-mail Notification and setup as shown in screenshot. You can set your own triggers also, every option or setting in self explanatory , configure it as per your requirement.

configure_extended_email

configure_extended_email

configure_extended_email

That's it you have successfully configured email settings, Lets set this up in our pipeline or jobs.

Step 5 — Configure Extended Email Notification in jenkins job

From step 3 in add post-build action and select Editable Email Notifications.

configure_extended_email_injob

Once it is added in build action save it.

configure_extended_email_injob

Now you will receive custom email for each of your job actions.

Problems that you might face while sending test email from Jenkins

Error 1 - Unable to connect to smtp server

java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
        Caused: javax.mail.MessagingException: Could not connect to SMTP host: smtp.pepipost.com, port: 25;

Solution: Try telnetting SMTP server on different port 587, 2525, 25 etc. if that works change SMTP port in your configuration.

Error 2 - SSL connection is blocked

If using port 587, SSL must be turned on.

com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. x8sm31507336pfn.106 - gsmtp

Solution: Turn on SSL from configurations.

Error 3

If your jenkins is running on http port you may get below error.

javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
    at sun.security.ssl.InputRecord.handleUnknownRecord(Unknown Source)

Solution : Either host Jenkins or HTTPS/change port to 465,

Error 4

If you are using Gmail as SMTP server you may below error:

javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials r2sm51378882pfq.60 - gsmtp

Solution : If you have entered wrong password or username correct it. And in Gmail allow less secure apps to login or install Jenkins to use HTTPS.

Conclusion

Now you can successfully configure email notifications for your Jenkins build/test/deploy pipelines.

Recent Posts

Leave a Comment

We are always looking for fresh talent to contribute to our blog. If you have a knack for writing and a passion for email marketing, we would love to have your post on our Guest Blog .

Submit a Guest Post
Pepi thinking

Start typing and press Enter to search

Thank you for your details!

Fill out your information below, and we will send you a PepiAlert, that will describe your domain’s email deliverability situation. Please note that your email address must match the domain, or the domain must be owned by the company matching the email address. We have the right to refuse the request, if we can’t verify the information.

*All fields are required