I’m having trouble getting Jenkins to send email notifications through Gmail SMTP. Every time I try to test the configuration, I get a connection refused error. Here’s what I have configured:
SMTP server - smtp.gmail.com
Default user e-mail suffix - @gmail.com
Sender E-mail Address - Build Server <[email protected]>
Use SMTP Authentication - yes
User Name - myemail
Password - my******password
Use SSL - yes
SMTP Port - 587
Reply-To Address - [email protected]
Charset - UTF-8
The test keeps failing with a connection refused message:
javax.mail.MessagingException: Could not connect to SMTP host: 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 enabled. Has anyone successfully configured Jenkins with Gmail SMTP? What could be causing this connection issue?
sounds like jenkins can’t reach gmail’s servers at all. I had the same issue when jenkins was behind a proxy - connection refused is totally different from auth failure. check if you need proxy settings in jenkins system config. also make sure you’re using an app password from your google account settings, not your regular password. google killed less secure apps so normal passwords don’t work anymore.
Connection refused usually means network issues, not auth problems. I hit this same error with Jenkins behind our corporate firewall. First, check if your Jenkins box can actually reach Gmail’s SMTP servers - run telnet smtp.gmail.com 587 from the Jenkins machine. If that fails, your firewall’s probably blocking outbound SMTP traffic. Also, Google killed the “less secure apps” setting in May 2022, so you can’t use your regular Gmail password anymore. You’ll need to generate an App Password from your Google Account security settings and use that instead. Your config looks fine, but double-check you’re using the App Password and test that network connection first.
Had the exact same issue last month with our Jenkins migration. The connection refused error made me think it was auth-related, but it wasn’t. Our Jenkins server was on a restricted network that blocked outbound connections on port 587. Switching to port 465 with SSL instead of port 587 with TLS fixed it. Some networks handle SSL differently than STARTTLS. Also check if Jenkins is running in Docker - I’ve seen container network settings block SMTP connections even when the host connects fine. Try the port change first, then verify network connectivity from Jenkins itself.