P H O T O N

CONSOLE

Loading

Infrastructure Troubleshooting Guide

How to Fix 'SMTP Connection Timed Out'
Diagnosing Port 25, 465 & 587 Firewall Blocks

Resolve outgoing connection hangs, unblock egress ports on AWS EC2, DigitalOcean, and GCP, and configure rock-solid STARTTLS relaying in minutes.

6 min read • AWS, GCP, DO, Azure, Linux • Verified Terminal Commands
Direct Answer: Fixing SMTP Connection Timeouts

SMTP connection timeouts occur when outgoing TCP SYN packets fail to receive an acknowledgment (SYN-ACK) from the destination mail server within 30 to 60 seconds. In over 80% of cloud-hosted applications (AWS EC2, DigitalOcean, Linode, Google Cloud), this is caused by cloud providers silently dropping outbound traffic on TCP port 25. To fix it, switch to Port 587 with STARTTLS or Port 465 with SSL/TLS, and route traffic through an authenticated smart host relay.

1. What Causes SMTP Connection Timeouts?

When your backend application or local Mail Transfer Agent (MTA) attempts to send an email, it initiates a standard TCP three-way handshake:

  1. SYN: Your server sends a synchronization packet to the mail server on port 25, 465, or 587.
  2. SYN-ACK: The mail server responds with an acknowledgment packet.
  3. ACK: Your server establishes the connection and waits for the SMTP 220 service banner.

If an intermediate firewall or ISP gateway silently drops the initial SYN packet without returning an immediate RST (reset) packet, your client socket remains in the SYN_SENT state until the system TCP timeout expires. This generates errors such as:

Connection timed out [errno 110]
Error: Connection timeout after 30000ms
stream_socket_client(): unable to connect to tcp://smtp.example.com:25 (Connection timed out)
Net::SMTP: Connection timed out at /usr/share/perl5/Net/SMTP.pm

2. Why AWS, DigitalOcean, and GCP Block Port 25

If your web server is hosted on modern cloud infrastructure, outbound TCP port 25 is blocked by default at the hypervisor level:

Cloud Host Port 25 Default Policy Removal Process Recommended Workaround
AWS EC2 Strictly Blocked Requires manual AWS support request form with reverse DNS verification Use Port 587 or 465 via authenticated relay
DigitalOcean Strictly Blocked Permanently blocked on new accounts to prevent spam abuse Use third-party SMTP relay on Port 587
Google Cloud (GCP) Strictly Blocked Outgoing port 25 is never permitted on Compute Engine Route via authenticated SMTP smart host
Linode / Akamai Blocked by Default Requires manual ticket and identity check Switch to Port 587 with STARTTLS
Key Takeaway: Even if you open Port 25 in your local OS firewall (ufw or iptables), the cloud provider drops the egress packets before they ever leave their data center.

3. 3-Step Terminal Diagnostic Protocol

Before modifying application code, run these three diagnostic commands from your server terminal to pinpoint whether the block is at the DNS, TCP socket, or TLS handshake layer.

Step A: Test Low-Level TCP Reachability with Netcat

Verify if a TCP socket can complete the handshake to the mail server on submission port 587:

# Test Port 587 (Submission)
nc -zv mail.photonrelay.com 587

# Expected Success Output:
# Connection to mail.photonrelay.com 587 port [tcp/submission] succeeded!
Step B: Test STARTTLS Handshake with OpenSSL

Confirm that SSL/TLS certificates and cipher suites negotiate cleanly without timing out:

openssl s_client -connect mail.photonrelay.com:587 -starttls smtp -crlf

# Look for:
# 250-STARTTLS
# SSL-Session: Protocol TLSv1.3, Cipher TLS_AES_256_GCM_SHA384
# Verify return code: 0 (ok)
Step C: Trace Packet Routing with Traceroute

If netcat hangs indefinitely, trace the network path to detect where packets are being dropped:

traceroute -p 587 -T mail.photonrelay.com

4. Code Configurations: Switching to Port 587 / 465

Once you confirm Port 587 or 465 is reachable from your host, update your application's SMTP parameters:

Node.js (Nodemailer)
const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({
  host: "mail.photonrelay.com",
  port: 587,
  secure: false, // true for 465, false for 587
  auth: {
    user: process.env.PHOTON_SMTP_USER,
    pass: process.env.PHOTON_SMTP_PASSWORD
  },
  connectionTimeout: 10000 // 10s timeout safeguard
});
PHP / Laravel (.env)
MAIL_MAILER=smtp
MAIL_HOST=mail.photonrelay.com
MAIL_PORT=587
MAIL_USERNAME=your_api_user
MAIL_PASSWORD=your_api_secret
MAIL_ENCRYPTION=tls
MAIL_TIMEOUT=15
Postfix Relayhost (/etc/postfix/main.cf)
relayhost = [mail.photonrelay.com]:587
smtp_use_tls = yes
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

5. Checking Local Firewalls & Cloud Security Groups

If you still experience timeouts even on port 587, check your local server firewall rules to ensure outbound TCP connections are permitted:

# Allow outbound Port 587 in UFW (Ubuntu/Debian)
sudo ufw allow out 587/tcp
sudo ufw allow out 465/tcp
sudo ufw reload

# Check status
sudo ufw status verbose

In AWS EC2, navigate to EC2 Management Console → Security Groups → Outbound Rules and ensure your security group includes an outbound rule for TCP port 587 (or all traffic) to 0.0.0.0/0.

Tired of SMTP Timeout Headaches & Port 25 Blocks?

PhotonRelay provides globally distributed Anycast edge relay endpoints on ports 587, 465, 2525, and 8025. Send high-volume transactional emails with sub-700ms delivery and zero cloud port blocks.

7. Frequently Asked Questions

Major cloud hosting platforms block outbound traffic on TCP port 25 by default to prevent spam botnets and IP blacklist contamination. Production applications should route email through authenticated relay services over port 587 (STARTTLS) or port 465 (implicit TLS) instead.

Port 587 with STARTTLS (RFC 6409) is the modern standard for email submission and has the highest network compatibility across corporate and cloud firewalls. Port 465 uses direct TLS encryption from initial socket connection and is also widely supported.

Run 'nc -zv mail.photonrelay.com 587' on Linux/macOS or 'Test-NetConnection -ComputerName mail.photonrelay.com -Port 587' in PowerShell. A successful connection will report 'Connection to mail.photonrelay.com port 587 [tcp/submission] succeeded!'.