What Port 25 Does
Port 25 is the original SMTP port. When a mail server has a message for another domain, it looks up the domain's MX record, connects to port 25 of that host, and hands the message over. No login is involved: the receiving server accepts mail addressed to its own domains and decides how far to trust the sender.
Port 25 has two directions on a server, and they are separate questions:
- Outgoing 25: your server delivers mail straight to other mail servers.
- Incoming 25: other mail servers deliver mail for your domain to your server.
Why Outgoing Port 25 Is Often Blocked
A compromised machine that can connect to port 25 can send spam directly to every mail server on the internet. To stop that, home internet access providers and many server providers restrict outgoing port 25. Some open it on request after a review of the planned use; others keep it closed. Check with your provider before you plan direct delivery.
Ports 587 and 465 are meant for sending with a login and are usually not affected. Port-by-port detail is in SMTP ports.
Test Outgoing Port 25 from Your Server
Find a mail host to test against, then try to connect:
dig +short MX example.com
nc -vz -w 5 mail.example.com 25
Use a host name from the first command's output in place of mail.example.com. How to read the result:
| Result | Meaning |
|---|---|
| Connected or succeeded | Outgoing 25 is open |
| Timed out | Most likely blocked |
| Refused | Reached, nothing listening |
A time-out can also mean the remote host is down, so try a second domain before you draw a conclusion. To see the server's 220 greeting line, connect with telnet or with nc mail.example.com 25, then type QUIT.
What to Do When It Is Blocked
- Ask your provider whether port 25 can be opened for your server and what they need to know.
- Or send through a relay service on port 587 with a login. Your server then needs only outgoing 587, and the relay takes care of delivery and reputation.
Relay Through Postfix on Port 587
For Postfix, a relay is a few lines in /etc/postfix/main.cf. Keep a copy of the file before you edit it:
relayhost = [smtp.example.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
Put the login in /etc/postfix/sasl_passwd as one line, [smtp.example.com]:587 username:STRONG_PASSWORD, then protect and index the file and reload:
sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
sudo postfix check
sudo systemctl reload postfix
On AlmaLinux and Rocky Linux 10, Postfix no longer supports hash: tables; write lmdb: in its place. If the mail log says "no mechanism available" or "no worthy mechs found", install the SASL modules: libsasl2-modules on Debian and Ubuntu, cyrus-sasl-plain on AlmaLinux and Rocky Linux.
What Direct Sending Also Needs
An open port 25 is only the start. Receiving servers check the sender's IP address before they accept mail, and mail from a badly set up server lands in spam or is refused. At minimum the server needs reverse DNS for its IP address that names the mail host, and the host name must point back to the same address; see what is reverse DNS. The domain also needs an SPF record listing the server and DKIM signatures on outgoing mail.
Incoming Port 25 for Receiving Mail
To receive mail for your domain, the MX record must name your server and incoming port 25 must be open. Incoming 25 is restricted less often than outgoing 25, but if mail does not arrive, check with your provider. Open it in the firewall only on the server that runs the mail service. On Ubuntu and Debian:
sudo ufw allow 25/tcp
On AlmaLinux and Rocky Linux:
sudo firewall-cmd --permanent --add-service=smtp
sudo firewall-cmd --reload
Check that the mail service listens on the public address with sudo ss -ltnp 'sport = :25'. Users of your mail server should send their own mail on port 587, not on 25.