Why Is My Gmail SMTP Timing Out on Render?

0
140
Asked By CuriousCoder42 On

I'm having a weird issue with my Node.js + Express app that sends OTPs via email using Gmail's SMTP. It works perfectly on my local machine, but when I deploy it on Render, I encounter a timeout every time the app tries to connect to the SMTP server. Here are the details:

- **SMTP server**: smtp.gmail.com
- **Port**: 465 (SSL)
- **Authentication**: Gmail App Password (2FA enabled)
- **Email library**: Nodemailer 6.9.x with Node version 20.x running in a Docker container on Render.

I've set up Nodemailer like this:

```javascript
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS,
},
});
```

Locally, emails send without any issues. However, on Render, I consistently see a "Connection timeout after 60000ms" error. I've tried the following:
- Verified my environment variables on Render
- Tested ports 465 and 587
- Increased the timeout settings
- Added retry logic
- Checked for Gmail login block alerts in my account

The issue appears to be a timeout rather than a refused connection, and the credentials are definitely correct since they work fine locally.

I'm wondering if Gmail might be blocking Render's IPs, if I should switch to a different SMTP provider, or if there are any specific restrictions on using Render for SMTP? Should I consider moving to services like SendGrid or Mailgun? Any help would be greatly appreciated!

3 Answers

Answered By MailMaster188 On

Many cloud services block standard SMTP ports like 465 and 25 to avoid spam issues. You could request them to unblock these ports, or better yet, consider using services like Mailchimp or AWS SES for sending your emails.

Answered By NodeNerd88 On

Why not just go with SES or SendGrid? They make it so much easier to manage sending emails, and their IPs are established, so you won't run into these blocking issues. Spin up your own SMTP server if you're up for it, but those options are much quicker.

Answered By TechExplorer99 On

I ran into a similar problem using Render's free version. It seems like Gmail SMTP gets blocked. I didn't dig too deep for a solution, but switching to SendGrid worked for me. It's definitely worth a try!

TechieTim88 -

Yeah, Render blocks SMTP ports in their free tier to limit abuse. Using SendGrid's HTTP port for sending OTPs was a game changer for me!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.