Home UbuntuHow to Set Up Postfix as a Send-Only Mail Server on Ubuntu

How to Set Up Postfix as a Send-Only Mail Server on Ubuntu

by Knowledge Base Linux
How to Set Up Postfix as — How to Set Up Postfix as a Send-Only Mail Server on Ubuntu

This article covers How to Set Up Postfix as in detail. A send-only mail server on Ubuntu is the pragmatic middle ground between “no email at all” and running a full mail server. Your server needs to send password-reset messages, cron reports, monitoring alerts and application notifications, but it does not need to receive mail, store mailboxes or fight the spam wars. Postfix configured as a send-only mail server on Ubuntu does exactly that: it accepts mail from local applications and delivers it to the internet, while refusing connections from outside senders. This guide covers the installation, the lockdown settings, DNS records and delivery testing.

Why Run a Send-Only Mail Server on Ubuntu? – How to Set Up Postfix as

A full mail server with Dovecot, spam filtering and webmail is one of the most maintenance-heavy services you can self-host. A send-only mail server on Ubuntu removes nearly all of that burden. There are no user mailboxes to secure, no inbound spam to filter and no open relay risk when it is configured correctly. Typical users are WordPress and WooCommerce sites, backup scripts that mail their results, and update systems such as the one in our automatic security updates guide, which can email you after every patch run.

Prerequisites – How to Set Up Postfix as

  • An Ubuntu 20.04, 22.04 or 24.04 server with sudo access.
  • A fully qualified domain name (FQDN) for the server, for example server1.example.com.
  • Access to your domain’s DNS to add an SPF record.
  • Outbound TCP port 25 open at your provider. Some VPS hosts block it by default; check before you start.

Step 1: Set the Server Hostname

Receiving mail servers judge you by your hostname and reverse DNS. Set a proper FQDN and make sure it resolves to your server:

sudo hostnamectl set-hostname server1.example.com
grep 127.0.1.1 /etc/hosts || echo "127.0.1.1 server1.example.com server1" | sudo tee -a /etc/hosts

Ask your hosting provider to set the reverse DNS (PTR record) of your server IP to the same name. A mismatch between hostname, forward DNS and PTR is the single most common reason self-sent mail lands in spam folders.

Step 2: Install Postfix

sudo apt update
sudo DEBIAN_FRONTEND=noninteractive apt install postfix mailutils -y

The installer asks for a configuration type and a system mail name. Choose Internet Site and enter your domain, for example example.com. We tighten the configuration in the next step, so the defaults are a fine starting point.

Outbound email from a send-only mail server on Ubuntu

Step 3: Lock Postfix Down to Send-Only

Edit /etc/postfix/main.cf and set the key parameters below. The decisive one is inet_interfaces: binding Postfix to the loopback interface means it listens only for mail submitted locally and is invisible to the internet:

myhostname = server1.example.com
mydestination = $myhostname, localhost
inet_interfaces = loopback-only
inet_protocols = ipv4
mynetworks = 127.0.0.0/8 [::1]/128
relayhost =

An empty relayhost means Postfix delivers directly to the recipient’s mail server. Apply the changes:

sudo postfix check
sudo systemctl restart postfix
sudo ss -tlnp | grep :25

The last command must show port 25 bound to 127.0.0.1 only. If it shows 0.0.0.0, the loopback setting did not apply and the server is exposed.

Step 4: Route Root’s Mail to a Real Inbox

System mail for root (cron output, logwatch, update alerts) should land in an inbox you actually read. Add an alias and rebuild the alias database:

echo "root: [email protected]" | sudo tee -a /etc/aliases
sudo newaliases

Step 5: Add an SPF Record

SPF tells receiving servers which IPs may send mail for your domain. Add a DNS TXT record on the domain your mail is sent from:

example.com.  TXT  "v=spf1 ip4:203.0.113.10 a -all"

Replace the IP with your server’s public address. Together with matching PTR and hostname from Step 1, SPF gives you a respectable baseline for deliverability without DKIM complexity. If your provider blocks outbound port 25, the standard workaround is a relay: set relayhost to an external SMTP service (Amazon SES, Brevo, your ISP’s smarthost) with SASL credentials and let it deliver for you.

Step 6: Test Delivery

echo "Test body from the new send-only server" | mail -s "Postfix test" [email protected]
sudo tail -f /var/log/mail.log

Look for status=sent in the log and check the test message arrived, then inspect the queue behaviour with mailq, which should be empty. Send a second test to a Gmail or Outlook address and check the spam folder, because those providers are the strictest judges of a new sender.

Troubleshooting

Mail sits in the queue as deferred. Read the reason in /var/log/mail.log: connection timeouts usually mean outbound port 25 is blocked by the provider, while DNS errors point at a broken resolver.

Messages are rejected with “cannot find your hostname”. Your PTR record is missing or does not match myhostname. Fix reverse DNS at the provider panel, not on the server.

Local apps cannot send. Confirm Postfix is running (systemctl status postfix) and that the application uses /usr/lib/sendmail or SMTP on localhost:25. Also protect the machine itself with Fail2Ban so a compromised account cannot turn your sender into a spam cannon.

Conclusion

A Postfix send-only mail server on Ubuntu gives your applications and system services a reliable voice without the weight of a full mail stack. Set a clean hostname and PTR, bind Postfix to loopback, publish SPF, and prove delivery with real tests before you rely on those alerts. For every configuration parameter, the official Postfix documentation is the authoritative reference.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.