Gmail SMTP connection timeout issue with Nodemailer

Getting timeout errors when sending emails through Gmail SMTP

I’m experiencing connection timeouts when trying to send emails using Nodemailer with Gmail SMTP. This is really frustrating because the same setup worked fine in my previous project, but now even that old project is failing with identical timeout errors.

I’ve tested with multiple Gmail accounts - some with 2FA enabled, one configured with XOAuth, and another with less secure apps enabled. All of them result in the same timeout problem.

Here’s my current configuration:

const mailConfig = {
  service: "Gmail",
  connectionTimeout: "7000",
  greetingTimeout: "7000",
  auth: {
    user: myEmailAddress,
    pass: myAppPassword
  },
  secure: true,
  debug: true
};

And here’s how I create the transport:

const transporter = nodemailer.createTransport(smtpTransport(mailConfig), () => {
  console.log('Transport created');
});

The callback function never executes, even with console.log statements inside.

I tested the connection manually using:

openssl s_client -crlf -connect smtp.gmail.com:465

This command times out on my machine, but works perfectly when my friend tries it on his computer. This suggests the issue is specific to my system rather than Gmail’s servers.

I’ve already disabled my firewall and tried different ports without success. Any ideas what could be causing this local connection issue?

Had this exact problem a few months back - turned out my antivirus was blocking outbound SMTP connections. Even with Windows Defender firewall disabled, my third-party antivirus was still silently blocking it. Try temporarily disabling all security software, including email protection modules. Also check if you’re on a corporate network or using proxy settings that might intercept SSL connections. Since openssl times out on your machine but works elsewhere, something on your local system is blocking the connection before it hits your ISP.

yeah, sounds like ur isp might be blocking the smtp ports. try using a vpn or mobile hotspot to see if that helps. if it does, reach out to ur isp to get those ports unblocked.

Had the exact same issue last year. DNS resolution conflicts on my local machine were the culprit. Switch to explicit host/port instead of the service shortcut - use host: "smtp.gmail.com" and port: 465 instead of service: "Gmail". Check if you’ve got DNS filtering or parental controls running that might block SMTP connections. Since the openssl command works on your friend’s machine but not yours, something’s intercepting connections at the system level. Try flushing your DNS cache: ipconfig /flushdns on Windows or sudo dscacheutil -flushcache on Mac.