Sending application mail from your server

Password resets, order receipts and alerts all depend on outgoing mail. A small, send-only setup handles them without running a full mail server.

Do I need a full mail server to send email?

No. An application only needs something that accepts a message locally and passes it on. A send-only Postfix does exactly that: it listens on localhost, queues messages, retries when a receiver is busy and logs every delivery. It never accepts mail from the internet, so there is nothing for spammers to abuse and no mailbox to look after.

How do I set up a send-only Postfix?

Install it, choose the internet site profile, and restrict it to the loopback interface. On Debian and Ubuntu the installer asks for a system mail name; use the domain your messages come from.

DEBIAN_FRONTEND=noninteractive apt install -y postfix
postconf -e inet_interfaces=loopback-only myhostname=app1.example.com mydestination= smtp_tls_security_level=may
systemctl try-restart postfix

On AlmaLinux and Rocky Linux, dnf install postfix and the same postconf lines apply; enable the service with systemctl enable --now postfix. Applications then send through /usr/sbin/sendmail or SMTP on 127.0.0.1 port 25.

Should my server deliver directly or through a relay?

Either works; the choice depends on volume and how much reputation work you want to do. Direct delivery from your own IPv4 address costs nothing and keeps everything in your hands, but a new address needs correct DNS records and a gentle start, as described in Mail server deliverability. An outside relay service that you already use handles reputation for you, and Postfix forwards to it over the authenticated submission port.

ApproachStrengthsWhat you manage
Direct from your IPNo extra cost, full logs, no outside dependencyReverse DNS, SPF, DKIM, DMARC, sending pace
Authenticated relayReputation handled by the relay, simple setupRelay credentials, SPF include for the relay

How is a relay on the submission port configured?

Point Postfix at the relay, give it the credentials in a protected map file and require TLS. The example uses a placeholder host; your relay documents its own name.

postconf -e 'relayhost=[mx-out.relay.example]:587' smtp_sasl_auth_enable=yes smtp_sasl_security_options=noanonymous smtp_tls_security_level=encrypt
postconf -e smtp_sasl_password_maps=hash:/etc/postfix/relay_auth smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt
echo "[mx-out.relay.example]:587 sender01:REPLACE_ME" > /etc/postfix/relay_auth
chmod 0600 /etc/postfix/relay_auth; postmap hash:/etc/postfix/relay_auth
postfix reload

Install libsasl2-modules on Debian and Ubuntu, or cyrus-sasl-plain on Enterprise Linux, if the log reports that no SASL mechanism is available.

How do I see whether mail went out?

Read the mail log and the queue. Each message gets a queue ID; follow it through the log to see the receiving server's answer. status=sent with a 250 code means the receiver accepted it.

journalctl -u postfix --since "1 hour ago" | grep -E 'status=|reject'
postqueue -p
postcat -q 4F2B1A0C3D | head -n 30
echo "test body" | mail -s "relay test" ops@example.com

A growing queue with deferred entries means receivers are refusing or slowing you down; the text after said: explains why. Flush once the cause is fixed with postqueue -f.

What must the sender domain publish in DNS?

At minimum an SPF record that includes your server or relay, and a DKIM signature. With direct delivery, the reverse DNS of the IPv4 address should match myhostname; you set it on the server page of the console. Using a subdomain for application mail, such as notify.example.com, keeps its reputation separate from staff mail on the main domain.

How do I stop a compromised script from spamming?

Limit what the local Postfix will send and watch the rate. A web application that suddenly sends thousands of messages is the most common sign of an abused contact form or a compromised plugin. Postfix can cap messages per minute per client, and a cron check on queue size catches the rest.

postconf -e "smtpd_client_message_rate_limit = 120"
postconf -e "anvil_rate_time_unit = 60s"
[ "$(postqueue -j | wc -l)" -gt 500 ] && echo "mail queue large on $(hostname)"

If spam did go out, stop Postfix, clear the queue of the bad messages with postsuper -d, find the script, and follow Respond to a compromised server.

What about IPv6 for outgoing mail?

Pick one protocol and do it properly. Our servers have an IPv6 block, and Postfix will use it when a receiver publishes IPv6 mail servers. Because reverse DNS in the console covers the IPv4 address, the dependable setting for outgoing mail is postconf -e "inet_protocols = ipv4", which keeps every delivery on the address whose PTR you control. The IPv6 and reverse DNS on your server article covers the IPv6 side in more detail.

Related pages

Mail server deliverability

Keep mail from your own server out of spam folders: DNS records, reverse DNS, sending limits and a clean outbound path.

Read more

IPv6 and reverse DNS on your server

Configuring the IPv6 block that comes with every machine and setting the reverse DNS name of its IPv4 address from the console.

Read more

Respond to a compromised server

What to do in the first hour after you suspect an intruder on a rented machine: contain, preserve evidence, rebuild and close the hole.

Read more

Essential servers

Affordable bare metal for websites, development and first production apps.

from $38.40 a monthRead more

Questions and answers

Can my server send email directly to the internet?

Yes. Each server has its own IPv4 address with reverse DNS you set in the console. Add SPF, DKIM and DMARC and start with modest volumes.

What is a send-only Postfix?

A Postfix installation that listens on localhost only. Applications hand it mail, and it queues and delivers outward without accepting mail from the internet.

Should I use port 25 or 587 to reach a relay?

Use 587 with authentication and TLS for relays. Port 25 is for server-to-server delivery.

How do I check whether a message was delivered?

Find its queue ID in the mail log. status=sent with a 250 response means the receiving server accepted it.

How do I prevent a hacked form from sending spam?

Set a per-client message rate limit in Postfix, alert on queue size, and keep web applications and plugins updated.