By Greg Nowak. Updated 10 November 2026.
A password reset that never arrives becomes a support request. An invoice in spam can delay payment. Reliable server email needs a clear path from the application to the recipient, with someone responsible when delivery fails.
For websites and scripts that need local mail submission, Postfix with an authenticated SMTP relay is a practical choice. Postfix queues messages and retries temporary failures; the provider handles onward delivery. Your team still owns sender settings, DNS authentication, and failure handling.
Choose the delivery route you can maintain
| Route | Best fit | Your ongoing responsibility |
|---|---|---|
| Postfix with SMTP relay | Scripts and applications need local submission and queueing | Server configuration, credentials, DNS, and bounces |
| Provider API | The application has a maintained integration | API credentials, application retries, and delivery events |
| Direct SMTP delivery | A team deliberately runs public mail infrastructure | IP reputation, reverse DNS, port 25 access, and receiver policies |
Check the relay's sending limits, permitted message types, domain verification, and delivery logs. For agency projects, agree who owns the provider account and DNS access before implementation. A working setup should be straightforward to hand over.
Configure Postfix for an outbound-only server
This example is for applications on a dedicated Debian or Ubuntu host. Back up /etc/postfix first. Review existing receiving services and custom routing before applying it to an established mail server.
sudo apt update
sudo apt install postfix mailutils libsasl2-modules ca-certificates
postconf -m
postconf default_database_typeConfirm that postconf -m lists hash. Otherwise, use a supported indexed type and its generated database filename throughout.
Edit /etc/postfix/main.cf, replacing the example hostname, domain, and relay endpoint:
myhostname = app01.example.com
myorigin = example.com
mydestination =
inet_interfaces = loopback-only
relayhost = [smtp.provider.example]:587
smtp_tls_security_level = secure
smtp_tls_secure_cert_match = nexthop
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_tls_wrappermode = no
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwdThe Postfix null-client pattern disables local domain delivery with an empty mydestination and limits SMTP listening to loopback. Containers have their own localhost: give them an explicit submission route rather than broadly exposing the listener.
Brackets prevent an MX lookup for the relay. Port 587 uses STARTTLS; if your provider specifies implicit TLS on port 465, update the port here and in the credentials file, and set smtp_tls_wrappermode = yes.
Require encryption and verify the relay's identity. The Postfix TLS documentation distinguishes encrypt, which does not require a trusted, matching certificate, from secure. These settings require a trusted certificate matching the configured relay hostname. Fix certificate errors rather than weakening verification. This policy is for a known relay, not general direct delivery.
Protect credentials and validate the configuration
Use the provider's SMTP credentials; they may differ from its dashboard login. Create or edit the file without deleting existing entries:
sudo sh -c 'umask 077; touch /etc/postfix/sasl_passwd'
sudo chown root:root /etc/postfix/sasl_passwd
sudo chmod 600 /etc/postfix/sasl_passwd
sudoedit /etc/postfix/sasl_passwdAdd your credentials using exactly the same brackets and port as relayhost:
[smtp.provider.example]:587 USERNAME:PASSWORDBuild the lookup database and check the configuration:
sudo sh -c 'umask 077; postmap hash:/etc/postfix/sasl_passwd'
sudo chown root:root /etc/postfix/sasl_passwd.db
sudo chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
sudo postfix check
sudo systemctl restart postfix
postconf -nThe Postfix SASL guide explains credential lookup and rebuilding maps. Both files contain sensitive credentials; protect their backups and rebuild the database after rotation. Review postconf -n for inherited routing or TLS overrides.
Authenticate the domain before testing delivery
Gmail's sender guidelines require SPF or DKIM for all senders to personal Gmail accounts, and SPF, DKIM, and DMARC for bulk senders. Use all three as your baseline:
- Verify your domain and enable the provider's DKIM signing.
- Follow its SPF instructions; merge authorised services into one SPF record per relevant domain.
- Check that the visible From domain aligns with the domain authenticated by SPF or DKIM.
- Start DMARC with reporting and
p=none; review legitimate senders before tightening enforcement.
For contact forms, send From your own authorised address and put the visitor's address in Reply-To. The relay provider normally manages reverse DNS for its delivery IPs.
Test the customer journey, not just the command
Send to an external mailbox you control, using an authorised sender:
echo "Postfix relay test" | mail \
-s "Postfix delivery test" \
-r [email protected] \
[email protected]
sudo postqueue -p
sudo tail -f /var/log/mail.logIn GNU Mailutils, -r sets the return address; other implementations can differ. If mail logs go to the journal, use sudo journalctl -f and locate Postfix messages.
Follow the queue ID. Here, status=sent means the relay accepted the message. Check provider events, the destination mailbox, spam placement, and authentication headers. Then trigger a real password reset or invoice: the application may bypass Postfix or use another sender. A reset arriving after its link expires still fails the customer.
Give delivery a named owner
Monitor queue growth, the oldest deferred message, and provider failures. Investigate authentication errors, timeouts, and limits before repeatedly flushing the queue. Monitor the envelope return address or process provider bounce events. Send critical delivery alerts through an independent channel.
Record account ownership, DNS access, credential rotation, and tested workflows. Give system alerts explicit, authorised senders and monitored recipients; do not assume mail to local root reaches a person. Repeat checks after migrations.
If responsibility is scattered across hosting, code, and DNS, Greg can help review the delivery path and agree a practical setup and handover. Talk to Greg about your server email.
Related on GrN.dk
- NGINX Can Read JSON Before Routing—Should It Handle Your AI API?
- Sending Mail with Drupal: A Reliable Setup for Business-Critical Email
- Apache 2.4.68: What to Check Before You Call It Patched
Need help with this kind of work?
Talk to Greg about your server email Get in touch with Greg.