Linux

How to fix Could not connect to SMTP host (CSF Firewall – Linux)

This guide helps system administrators and developers troubleshoot and fix SMTP connection issues on Linux servers caused by CSF firewall. It covers common causes, required SMTP ports, CSF configuration changes, and testing methods to ensure reliable email delivery.

Most common cause

CSF firewall is blocking outbound SMTP ports, so your server cannot connect to the SMTP server.

Common SMTP ports:

  • 25 – often blocked

  • 465 – SMTPS (SSL)

  • 587 – SMTP (TLS, recommended)

Test if SMTP port is blocked

Run on your server:

telnet smtp.gmail.com 587

or

nc -vz smtp.gmail.com 587

If you see:

Connection timed out 

→ CSF is blocking the connection.

Disable SMTP blocking in CSF

Open CSF config:

nano /etc/csf/csf.conf

Find:

SMTP_BLOCK = "1"

Change to:

SMTP_BLOCK = "0"

SMTP_BLOCK = 1 blocks all outbound SMTP traffic

Allow SMTP outbound ports

Find this line:

TCP_OUT =

Make sure it includes SMTP ports:

TCP_OUT = "20,21,22,25,53,80,110,143,443,465,587,993,995"

Important ports:

  • 465

  • 587

Restart CSF

csf -r