I wanted to set up a server so that any local email (e.g. generated by cron jobs/systemd timers) would be forwarded to an external address, regardless of the user. I also wanted the from address to keep the system hostname whilst not allowing any external use of the mailserver.
It took me a while to figure out how to this, so I thought I’d share my method.
Here’s the config that can be used to do this on any NixOS host, after redefining the first two variables.
Emails to any user without a domain part are all sent to the forwarding address with a clear from address (e.g.
System administrator <email@example.com>).
First, the basic setup for a null client can be found in the postfix documentation. The example config would be translated into NixOS like so:
However, this rewrites firstname.lastname@example.org to email@example.com (due to
origin on line 5). I wanted to be able to see which host a mail concerns.