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://haypack.dev/<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.
Verschickt die Mail des Gasts – von der App, von Cron und vom System – über den eigenen
Smarthost (eigener Mailserver, Mailbox.org, Microsoft 365, …). Postfix nimmt Mail auf
127.0.0.1:25 ohne Anmeldung und über /usr/sbin/sendmail an, stellt sie in die Warteschlange
und gibt sie mit TLS und geprüftem Zertifikat weiter. Direkt ins Internet stellt es nie zu.
Relay setzen
In /etc/iac/settings.env, danach update:
mail_relay_host=smtp.example.org
mail_relay_port=587 # 587 (STARTTLS, Standard) oder 465 (TLS)
mail_relay_user=server@example.org
mail_relay_password=…
mail_from=server@example.org # optional, Standard: mail_relay_user
mail_root_to=admin@example.org # optional, Mail für root/Cron, Standard: mail_from
Jede Mail geht mit mail_from als Absender hinaus – die meisten Smarthosts nehmen nur ihr eigenes
Konto an. Solange das Relay nicht gesetzt ist, wartet die Mail in der Warteschlange (mailq) und
geht direkt nach dem update hinaus.
Benutzen
printf 'Subject: test\n\nhello\n' | sendmail root # Testmail an mail_root_to
mailq # wartende Mail
journalctl -t postfix/smtp # Zustellungen
Wenn keine Mail hinausgeht
journalctl -t postfix/smtp -n 20 | grep status= # warum sie wartet
postconf -h relayhost # [smtp.example.org]:587
535 … authentication failed: Benutzer oder Passwort sind falsch – oder das Postfach existiert nicht. Postfix versucht es alle paar Minuten erneut, und viele Anbieter sperren die Adresse nach einigen Fehlversuchen (dann:Connection refused). Das zuerst stoppen:postsuper -d ALL deferredverwirft die wartende Mail. Die Anmeldung im Webmail des Anbieters prüfen,settings.envkorrigieren – der Wert steht so, wie er nach=steht, ohne Anführungszeichen –, dannupdateund eine Testmail schicken.- Das Modul ist nach ein paar Minuten weg: Ein von NetBox verwalteter Gast bekommt seine Module
aus dem Feld Modules seiner VM; iac-provisioner setzt eine Änderung mit
update -amzurück.mail-relaydort eintragen (updateweist darauf hin).
Apps schicken an 127.0.0.1, Port 25, ohne Anmeldung und TLS. Eigene Postfix-Parameter gehören in
/etc/postfix/main.local.cf (danach update). Wird das Modul entfernt, werden Postfix und
/etc/postfix samt der Mail in der Warteschlange entfernt.