Sending Mail from a Linux Server with Postfix: A Practical Relay Setup

Illustrated infographic summarizing: Sending Mail from a Linux Server with Postfix: A Reliable, Relay-First Setup

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
Choose according to what your team can support after launch.

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_type

Confirm 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_passwd

The 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_passwd

Add your credentials using exactly the same brackets and port as relayhost:

[smtp.provider.example]:587 USERNAME:PASSWORD

Build 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 -n

The 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.log

In 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

Need help with this kind of work?

Talk to Greg about your server email Get in touch with Greg.

Sources

Latest articles

See how SharePoint access changes reach internal AI search, and test how long revoked content can still appear in results, generated answers, and citations.

At month-end, reconcile Shopify Payments against your bank statement and e-conomic. Use the payout ID to trace fees, refunds, and payouts that reach your bank the following month.

Trace an intermittent NGINX 502 through Cloudflare, upstream attempts, and application logs so you can see where the request failed and who should pick it up.

Find the apps, scripts and printers that still send mail through Microsoft 365 with a mailbox password, then test a replacement before the December 2026 change.

Find subscriptions and insurance expenses in e-conomic that should be spread over several months. See how AI reads the supporting documents and how your finance lead approves the proposed allocations.

Before relying on an AI project briefing, check which files it covered. A practical workflow for tracking documents, recording gaps and verifying key claims.

Check whether your contact form rejects missing or invalid Turnstile tokens, handles failed checks for genuine users and delivers accepted enquiries to your team.

Compare Bing citations, identifiable AI visits and verified enquiries to see which pages deserve attention before you increase your AI search marketing budget.

Teamtailor is phasing out Riminder on 21 November 2026. Check your parser settings, contact fields and integrations, and make sure you have a process for deleting applicant data.

WordPress jobs running late? Learn how to separate scheduling problems, task errors and a growing backlog, then choose the right scheduler or runner.