Configuring Email Server in Jenkins using SMTP gmail
We will use the plugin named Email Extension Plugin to trigger our emails. Go to Manage Jenkins -> Manage Plugins -> Search for Email Extension Plugin -> Install.
With this plugin you can customize things such as when to send the email, who receives it, and what the email says.
Go to Manage Jenkins -> Configure System -> You will find a Email Notification tab. We need to fill in the details here.
- Select Advanced.
- SMTP Server : smtp.gmail.com
- Select Use SMTP Authentication
- Username : Your gmail Id
- Password : Your gmail password
- Select Use SSL
- SMTP Port : 465
- Reply-to-Address : your email id
- Charset : UTF-8
- Save
Screenshot below for the above configuration :
Yeah. So we are using smtp protocol to send/receive messages : The Simple Mail Transfer Protocol (SMTP) is an internet standard communication protocol for electronic mail transmission. Mail servers and other message transfer agents use SMTP to send and receive mail messages.
It should be no surprise to know that google provides a widely popular webmail i.e. Gmail and also an associated outgoing mail server which can be used to work with emails. To use smtp google you just need server, port, email id and password. Server and port remains same smtp.gmail.com and 465 respectively. Email id and password will change based on the account you want to use to run this server.
Now we are ready to use the mail server to send & receive emails in the Jenkins pipeline.
You may get errors while trying to use your gmail account. You need to provide third party applications access so that Jenkins can use your account as smtp server. This stackoverflow link helped me resolve the issue related to turning off two step verification and allowing less secure application to be used.
Screenshot example to use email in Jenkins pipeline :
In the above screenshot, if there’s any failure in unit test stage then an email will be sent to ‘vivek.sinless@gmail.com’ with the subject and body provided.
With that, we have setup a mail server in Jenkins pipeline. Please follow me to get more interesting and real tech content.
Happy learning. Cheers!