Troubleshooting Postfix SMTP Connection Timeout Errors on Ubuntu for Outbound Email


2 views

When setting up Mailman with Postfix on Ubuntu, many administrators encounter SMTP connection timeout errors when attempting to send emails. The log entries typically show multiple failed attempts to connect to remote SMTP servers:

Mar 30 16:35:30 server postfix/smtp[22572]: connect to gmail-smtp-in.l.google.com[74.125.142.26]:25: Connection timed out
Mar 30 16:37:31 server postfix/smtp[22572]: A0616100CCB: to=<example@gmail.com>, relay=none, delay=150, status=deferred

Several factors could be blocking your outbound SMTP connections:

  • Firewall blocking port 25 outbound
  • ISP restrictions on port 25
  • Incorrect DNS resolution
  • Network connectivity issues
  • Postfix misconfiguration

First, verify basic network connectivity:

telnet gmail-smtp-in.l.google.com 25

If this fails, try testing DNS resolution:

dig gmail-smtp-in.l.google.com

Try these adjustments in your /etc/postfix/main.cf:

# Increase connection timeout
smtp_connect_timeout = 30s

# Specify alternative ports
smtp_fallback_relay = [mail.example.com]:587

# Enable TLS
smtp_tls_security_level = may
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

If port 25 is blocked, configure Postfix to use submission port 587:

# In /etc/postfix/master.cf
submission inet n - - - - smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt

Ensure your firewall allows outbound connections:

sudo ufw allow out 25,465,587/tcp
sudo ufw allow out 53/udp

After making changes, test with:

sudo postfix reload
echo "Test email" | mail -s "Test" your@email.com

When examining Postfix SMTP connection attempts, we see a consistent pattern of timeouts across all Gmail MX records:

Mar 30 16:35:30 apott-server postfix/smtp[22572]: connect to gmail-smtp-in.l.google.com[74.125.142.26]:25: Connection timed out
Mar 30 16:36:01 apott-server postfix/smtp[22572]: connect to alt1.gmail-smtp-in.l.google.com[173.194.76.27]:25: Connection timed out
[...]

First, verify basic network connectivity to Gmail's SMTP servers:

# Test DNS resolution
dig gmail-smtp-in.l.google.com MX +short

# Test raw TCP connectivity
telnet gmail-smtp-in.l.google.com 25
timeout 5 nc -zv gmail-smtp-in.l.google.com 25

  • Outbound port 25 blocked by ISP (common with residential IPs)
  • Firewall rules (iptables/ufw) blocking outbound SMTP
  • Network security groups in cloud environments
  • Incorrect Postfix network configuration

Review these critical Postfix settings in /etc/postfix/main.cf:

# Verify these parameters
inet_interfaces = all
smtp_bind_address = 
smtp_bind_address6 = 
relayhost = 

If port 25 is blocked, try using Gmail's submission port (587) with authentication:

# In main.cf
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt

To isolate the issue, test SMTP communication manually:

openssl s_client -connect gmail-smtp-in.l.google.com:25 -starttls smtp -crlf
EHLO yourdomain.com
MAIL FROM: <test@yourdomain.com>
RCPT TO: <your@gmail.com>
DATA
Subject: Test
This is a test message
.
QUIT

For AWS EC2 instances:

# Request removal of port 25 restriction
aws sesv2 put-account-details --region us-east-1 \
--account-details '{
  "MailType": "MARKETING",
  "WebsiteURL": "https://yourdomain.com",
  "ContactLanguage": "EN",
  "UseCaseDescription": "Mailman mailing lists",
  "AdditionalContactEmailAddresses": ["admin@yourdomain.com"]
}'