Postfix

Relay a whole machine's outgoing mail into a sandbox — every application on it, without touching any of them.

1Point the relay at the sandbox

/etc/postfix/main.cf
# /etc/postfix/main.cf
relayhost = [smtp.mailclutch.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

The square brackets matter: they tell Postfix not to look up MX records for the host.

2Store the credentials

/etc/postfix/sasl_passwd
# /etc/postfix/sasl_passwd
[smtp.mailclutch.com]:587 mc_0000000000000000:pw_0000000000000000
sudo postmap /etc/postfix/sasl_passwd
sudo chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
sudo systemctl reload postfix

The host and port in sasl_passwd must match relayhost character for character, brackets included, or the lookup misses and Postfix sends unauthenticated.

3Send a test message

echo "Hello from Postfix." | mail -s "Sandbox check" anyone@example.com

tail -f /var/log/mail.log shows the delivery, and the sandbox shows the message.

Watch it land

Open the sandbox and the message is there — rendered HTML, plain text, raw source, attachments, and the SPF, DKIM and DMARC verdicts. It updates live, so you can leave it open next to your terminal.

Nothing is ever delivered onward, whatever address you send to; claim the inbox with an account and it stays.

Awaiting your email

Send from any address; it stops here rather than going onward. The inbox keeps what it catches for 24 hours.

What usually goes wrong

  • SASL support has to be built in

    postconf -a must list cyrus or dovecot. On Debian and Ubuntu that means the libsasl2-modules package.

  • Mail already in the queue

    Messages queued before the change keep their old destination until you run postqueue -f.

Official documentationPostfix — SASL README (opens in a new tab)