about summary refs log tree commit diff stats
path: root/content/post
diff options
context:
space:
mode:
authorAlan Pearce2020-09-11 20:17:15 +0200
committerAlan Pearce2020-09-11 20:17:15 +0200
commit07b2317669cdbdfa1579288c4bee2e8da6336b3c (patch)
tree9347c5bb53018e94a623054c7d99855ebf0c6ea7 /content/post
parentdc566c038ac231b81d3b5343f47bb07ed3e9989c (diff)
downloadwebsite-07b2317669cdbdfa1579288c4bee2e8da6336b3c.tar.lz
website-07b2317669cdbdfa1579288c4bee2e8da6336b3c.tar.zst
website-07b2317669cdbdfa1579288c4bee2e8da6336b3c.zip
New post: postfix as null client (NixOS)
Diffstat (limited to 'content/post')
-rw-r--r--content/post/postfix-as-null-client-with-external-catchall.md53
1 files changed, 53 insertions, 0 deletions
diff --git a/content/post/postfix-as-null-client-with-external-catchall.md b/content/post/postfix-as-null-client-with-external-catchall.md new file mode 100644 index 0000000..abc6bce --- /dev/null +++ b/content/post/postfix-as-null-client-with-external-catchall.md
@@ -0,0 +1,53 @@
1---
2title: 'Postfix on a NixOS null client with external catch-all'
3date: 2020-09-11T18:49:00+02:00
4Tags: ["development","git","nixos"]
5---
6I 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.
7
8It took me a while to figure out how to this, so I thought I'd share my method.
9
10Here's the config that can be used to do this on any NixOS host, after redefining the first two variables.
11
12```txt {linenos=table,hl_lines=["2-3"]}
13services.postfix = let
14 localUser = "example-user";
15 forwardingAddress = "user@external.domain";
16in
17{
18 enable = true;
19 destination = [];
20 domain = config.networking.domain;
21 virtual = ''
22 @${config.networking.hostName}.${config.networking.domain} ${localUser}
23 ${localUser} ${forwardingAddress}
24 '';
25 config = {
26 inet_interfaces = "loopback-only";
27 };
28};
29```
30
31Emails to any user without a domain part are all sent to the forwarding address with a clear *from* address (e.g. `System administrator <root@host.example.com>`).
32
33## Background
34
35First, the basic setup for a null client can be found in the [postfix documentation][0]. The example config would be translated into NixOS like so:
36
37```txt {linenos=table}
38services.postfix = {
39 enable = true;
40 destination = [];
41 domain = config.networking.domain;
42 origin = config.networking.domain;
43 relayHost = config.networking.domain;
44 lookupMX = true;
45 config = {
46 inet_interfaces = "loopback-only";
47 };
48};
49```
50
51However, this rewrites user\@hostname.example.com to user\@example.com (due to `origin` on line 5). I wanted to be able to see which host a mail concerns.
52
53[0]: http://www.postfix.org/STANDARD_CONFIGURATION_README.html#null_client