How to Install and Configure Email Notifications in Jenkins

Published on 2019-09-18ยท Updated on 2024-04-11

The author voluntarily contributed this tutorial as a part of Pepipost Write to Contribute program.

Introduction

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.
  3. Click on Manage Plugins.
  4. Select Email Extension and Email Extension Template Plugin and click Install Without Restart.

Once The Plugin Is Installed Let's Configure It With SMTP Servers So That Jenkin Emails Can Be Routed Via These SMTP Servers.

Step 2 - Configure Email Notifications

  1. Click on Manage Jenkins and then Configure system
  2. Scroll below till E-mail Notification and click on advanced. Setup up as shown in below screenshot and save it.

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.

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)

2) Click on Manage Plugins

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

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

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 the screenshot. You can set your own triggers also, every option or setting in self-explanatory, configure it as per your requirement.

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.

Once it is added in build action save it.

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 the wrong password or username correct it. And in Gmail allow less secure apps to log in or install Jenkins to use HTTPS.

Conclusion

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

Other Related Tutorial.

email content best practices

Grade My Email
Check your spam now?

Netcorecloud's toolkit is the solution to all your email problems.

Rishabh Mishra

Programming Guy! Your coding problem corresponder.

You can also explore

Netcore connects & unifies your data across all sources, connects to your marketing channels and provides you with control over AI Powered automation and personalization.

Deploy emails that are
screenshot worthy!

Stop settling for static emails - use Netcore's platform to create dynamic, interactive emails that convert.
Let's Deploy
Get Started Now