19
votes

I tried to configure jenkins to send email notification with gmail as the POP provider but I could not succeed

SMTP server - pop.gmail.com
Default user e-mail suffix - @gmail.com
Sender E-mail Address - Foobar CI <[email protected]>

Use SMTP Authentication - yes
User Name - your.email
Password - p******d

Use SSL - yes
SMTP Port - 995
Reply-To Address - [email protected]
Charset - UTF-8

Test failed with : Connection refused

javax.mail.MessagingException: Could not connect to SMTP host: pop.gmail.com, port: 995; nested exception is: java.net.ConnectException: Connection refused: connect

8
Can you try telnet smtp.gmail.com 995 to see if the port is open - Pulak Agrawal
Indeed I tried: telnet smtp.gmail.com 465 or telnet pop.gmail.com 995 and in both case I got connection failed. What should I do ? - Corinne Kubler
well if telnet is failing this clearly means your firewall is blocking the outbound port .. you need to work with your network admin to fix this. - Pulak Agrawal

8 Answers

35
votes

The hostname for the Google SMTP server is smtp.gmail.com and if you use SSL, then the correct Port is 465.

A POP server is usually just for receiving mails, not sending mails.

26
votes

Below are the updated gmail SMTP server configuration :

Gmail SMTP server address: smtp.gmail.com
Gmail SMTP user name: Your full Gmail address (e.g. [email protected])
Gmail SMTP password: Your Gmail password
Gmail SMTP port: 465
Gmail SMTP TLS/SSL required: yes

This configuration is working fine for me .

22
votes

The above configuration didn't work because of added security measures by google. An additional configuration is required in the Gmail account from which the mail is being triggered. This step authorizes apps like Jenkins to use the Gmail account.

https://support.google.com/accounts/answer/6010255

Go to the "Less secure apps" section in My Account. Next to "Access for less secure apps," select Turn on. (Note to G Suite users: This setting is hidden if your administrator has locked less secure app account access.)

After this emails were triggered successfully.

17
votes
  1. Obtain application specific password

    • sing-in to gmail account >> navigate to settings >> privacy and security settings

    • setup two step verification settings (because without two step verification we cannot generate application specific password)

    • after setting up two step verification setting in gmail account navigate back to security and privacy settings

    • click on application specific password >> give the name of the application in the drop down as Jenkins (google by default does not have any specific application password setting for Jenkins) >> this will generate password note down the password generated

Note : Since the Password has a overall control over you gmail account disclosing it may lead serious consequences

  1. Setup SMTP configuration for sending the gmail

    • navigate in the following path from dashboard after logging in manage Jenkins >> configure system >> scroll down to email notification section

    • enter the following parameters

      smtp server : smtp.gmail.com
      default user email suffix : @gmail.com
      
    • select advanced

    • check smtp authentication

      username : (Your gmail id)
      password : (application specific password generated from previous step)
      
    • check use SSL

      SMTP port : 465
      Reply to address : [email protected](optional)
      Charset : UTF-8 (by default it is UTF-8)
      
    • select Test configuration mail

      Test e-mail recipient : <enter recipient email id >
      

click on test configuration which will send a test mail to the recipient e-mail id

4
votes

The following screenshot illustrates the e-mail configuration you'd need to do to send e-mails from GMail.

The following screenshot illustrates the e-mail configuration you'd need to do to send e-mails from GMail.

4
votes

NOTICE

The latest mailer plugin version 1.24 has a bug, which causes test configuration failure(authentication required) even if you have the correct configuration. Download the 1.23 (.hpi file) version from Official website, then upload it from manage plugin->advanced. Restart jenkins, it should work well.

Only need to enable the less secure app access, there is no need to open 2-step verification.

2
votes

I successfully did this with Zapier on their free tier (without having to turn on "less secure apps" in gmail

  1. Install Jenkins Notification Plugin. You might need to restart Jenkins
  2. Go to Zapier and create a Jenkins trigger
  3. In Jenkins under your project: Configure -> Job Notifications, fill in the options. Using JSON seemed to work for me.
  4. Add Gmail action in Zapier. You should be able to set this up with single sign on in your gmail account.

PS. I have no reason to recommend Zapier other than that it is working for me, and there's a solution w/o comprimising my gmail account.

2
votes

Following settings are working fine for me.


Jenkis version: 2.204.1
Mailer Plug-in version: 1.30

SMTP settings:

SMTP Server - smtp.gmail.com
Use SMTP Authentication - checked
Username - [email protected]
Password - your-gmail-password for the above account>

NOTE: 2 factor authentication must be OFF and Less Secure application access must be ON in your account setting in google

Use SSL - checked
SMTP port - 465
Charset - UTF-8
Test Connection - provide the recipient email address