Setting up Gmail SMTP for Jenkins email alerts

I’m having trouble getting Jenkins to work with Gmail for sending build notifications. Every time I try to test the connection, it fails with a connection error.

Here’s what I configured:

SMTP Server: smtp.gmail.com
Email Domain: @gmail.com  
From Address: Build Server <[email protected]>

Authentication: enabled
Username: myaccount
Password: my_app_password

SSL: enabled
Port: 587
Reply Address: [email protected]
Encoding: UTF-8

The test keeps failing with this error message:

javax.mail.MessagingException: Cannot establish connection to SMTP server: smtp.gmail.com, port: 587;
  nested exception is:
    java.net.ConnectException: Connection refused: connect

I’ve double checked my Gmail settings and made sure less secure apps are allowed. Has anyone successfully set this up before? What am I missing in my configuration?

Check your Jenkins system config first - the port’s probably blocked at OS level. Hit this same issue when our IT had strict outbound rules that weren’t obvious until I dug deeper. Try switching to port 465 with SSL/TLS instead of 587. Port 465 works way more reliably with corporate networks and Jenkins setups in my experience. Make sure you’re using the full email as username, not just what’s before the @. One thing that got me - some Jenkins versions hate Gmail’s certificate chain. I had to update the Java keystore on our Jenkins server to include Gmail’s certs. Test this by temporarily disabling SSL verification to see if that’s your problem. If you’re still stuck, check Jenkins logs for detailed errors. That “connection refused” message is pretty generic - the real issue’s usually buried deeper in the stack trace.

Had this exact problem last month. Your Jenkins config isn’t the issue - Gmail killed support for “less secure apps” in May 2022. Even app passwords get rejected now unless you’re using OAuth2. Your settings look right, but Gmail won’t accept anything except proper OAuth2 authentication anymore. The Email Extension Plugin supports it, but setup’s a pain. Quick fix that worked for me: use a different SMTP provider while you figure out OAuth2. I switched to our company mail server, but SendGrid or Mailgun work too and they’re way easier to authenticate. If you’re stuck with Gmail, you’ll need to register Jenkins as an OAuth2 app in Google Cloud Console, grab client credentials, then configure the plugin for OAuth2 instead of basic auth. It’s documented but honestly pretty tedious.

Connection refused means Jenkins can’t reach Gmail’s SMTP server at all. Usually it’s a network or firewall issue, not authentication.

First, check if your Jenkins server can reach smtp.gmail.com on port 587. SSH into your Jenkins box and run:

telnet smtp.gmail.com 587

If it times out, you’ve got a network problem. Corporate firewalls love blocking SMTP ports.

Try port 465 with SSL instead of 587 with TLS. Sometimes works better depending on your network.

Honestly, I stopped wrestling with Jenkins email configs years ago. The whole thing’s painful and breaks constantly when Google changes security policies.

I moved all my notification stuff to Latenode. Handles Gmail way better and you can build flexible notification workflows. Trigger notifications based on build status, send to different channels, format messages however you want - and it actually works.

You can also integrate with Slack, Discord, or whatever your team uses without fighting Jenkins plugins. Way less headache.