24

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

3
  • Can you try telnet smtp.gmail.com 995 to see if the port is open Commented Nov 23, 2012 at 5:58
  • 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 ? Commented Nov 23, 2012 at 8:25
  • 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. Commented Nov 23, 2012 at 8:48

8 Answers 8

35

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.

3
  • 1
    In fact I got the same error if I use smtp.gmail.com. I tried both Commented Nov 23, 2012 at 8:27
  • As Pulak Agrawal wrote, in this case it is possible, that you have a firewall between your server and the internet, which is blocking that port.
    – dunni
    Commented Nov 23, 2012 at 10:01
  • 1
    You may need to login to your gmail account and under security "Allow Less Secure" apps. Commented Apr 30, 2021 at 23:17
27
  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

1
  • Thank you for the proper setup instructions.
    – Shraddha
    Commented Dec 31, 2020 at 20:15
26

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 .

1
23

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.

4
  • 2
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review Commented Mar 23, 2016 at 15:47
  • 1
    @MartinZabel Updated. Commented Sep 22, 2017 at 12:22
  • Thanks it worked for me : to be turned on here : myaccount.google.com/lesssecureapps
    – Tinmarino
    Commented Jun 18, 2020 at 6:10
  • 1
    Just for better visibility : the error message : javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 support.google.com/mail/?p=BadCredentials
    – Tinmarino
    Commented Jun 18, 2020 at 6:10
4

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

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.

1
  • Google is going to remove the feature that enables the access to apps that are less secure, starting from May, 30th 2022. Use password for specific apps instead. Commented Apr 11, 2022 at 9:35
2

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.