Published on 2019-09-18· Updated on 2021-12-15
The author voluntarily contributed this tutorial as a part of Pepipost Write to Contribute program.
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:
In Extended Email Notifications you can set triggers (e.g. build is unstable or before build), specify email subject, content and recipients.
This tutorial is based on Jenkins version 2.194 installed on localhost and using http port 8071.
Once The Plugin Is Installed Let's Configure It With SMTP Servers So That Jenkin Emails Can Be Routed Via These SMTP Servers.
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.
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.
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.
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.
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.
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.
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,
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.
Now you can successfully configure email notifications for your Jenkins build/test/deploy pipelines.
Netcorecloud's toolkit is the solution to all your email problems.
Netcore connects & unifies your data across all sources, connects to your marketing channels and provides you with control over AI Powered automation and personalization.