Mail relay (Postfix)
Postfix from Debian on localhost:25 and sendmail: apps, cron and system mail go out through your smarthost with TLS and login – never directly. Target: mail_relay_host, mail_relay_user, mail_relay_password in /etc/iac/settings.env
Add to a guest
In the guest as root – container and VM alike:
update --add-modules mail-relayRuns a normal update and installs the module on the way.
From the Proxmox node, without logging in:
pct exec <ID> -- update --add-modules mail-relay # container
ssh root@<IP> update --add-modules mail-relayChoose when creating a guest
Without a dialog, on the Proxmox node:
IAC_NONINTERACTIVE=1 var_modules=auto-update,mail-relay \
bash -c "$(curl -fsSL https://iac.heyer.systems/<app>/ct.sh)"var_modules replaces the app's preselection – keep auto-update in the list if you want it. Interactive: choose “advanced” in the dialog, or tick the module in the generator on the app page.
Remove
update --remove-modules mail-relayRemoves the module's packages, services, firewall rules and configuration again. Data stays. Apps that require the module keep it – it cannot be removed there.
Details
Sends the mail of the guest – from the app, cron and the system – through your smarthost
(your mail server, Mailbox.org, Microsoft 365, …). Postfix takes mail on 127.0.0.1:25 without
login and on /usr/sbin/sendmail, queues it and hands it on with TLS and a checked certificate.
It never delivers directly to the internet.
Set the relay
In /etc/iac/settings.env, then run update:
mail_relay_host=smtp.example.org
mail_relay_port=587 # 587 (STARTTLS, default) or 465 (TLS)
mail_relay_user=server@example.org
mail_relay_password=…
mail_from=server@example.org # optional, default: mail_relay_user
mail_root_to=admin@example.org # optional, mail for root/cron, default: mail_from
Every mail leaves with mail_from as sender – most smarthosts accept only their own account.
Until the relay is set, mail waits in the queue (mailq) and goes out right after the update.
Use it
printf 'Subject: test\n\nhello\n' | sendmail root # test mail to mail_root_to
mailq # waiting mail
journalctl -t postfix/smtp # deliveries
When mail does not go out
journalctl -t postfix/smtp -n 20 | grep status= # why it waits
postconf -h relayhost # [smtp.example.org]:587
535 … authentication failed: user or password are wrong – or the mailbox does not exist. Postfix tries again every few minutes, and many providers block your address after a few failed logins (then:Connection refused). Stop that first:postsuper -d ALL deferreddrops the waiting mail. Check the login in the provider’s webmail, fixsettings.env– the value stands as it is after=, without quotes – thenupdateand send one test mail.- The module is gone after a few minutes: a guest managed by NetBox gets its modules from
the field Modules of its VM; iac-provisioner sets back a change made with
update -am. Addmail-relaythere (updatewarns about this).
Apps send to 127.0.0.1, port 25, without login and TLS. Your own Postfix parameters go into
/etc/postfix/main.local.cf (then update). When the module is removed, Postfix and
/etc/postfix are removed with mail still in the queue.