about summary refs log tree commit diff stats
path: root/content
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
parentdc566c038ac231b81d3b5343f47bb07ed3e9989c (diff)
downloadwebsite-07b2317669cdbdfa1579288c4bee2e8da6336b3c.tar.lz
website-07b2317669cdbdfa1579288c4bee2e8da6336b3c.tar.zst
website-07b2317669cdbdfa1579288c4bee2e8da6336b3c.zip
New post: postfix as null client (NixOS)
Diffstat (limited to 'content')
-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 @@
+---
+title: 'Postfix on a NixOS null client with external catch-all'
+date: 2020-09-11T18:49:00+02:00
+Tags: ["development","git","nixos"]
+---
+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.
+
+```txt {linenos=table,hl_lines=["2-3"]}
+services.postfix = let
+  localUser = "example-user";
+  forwardingAddress = "user@external.domain";
+in
+{
+  enable = true;
+  destination = [];
+  domain = config.networking.domain;
+  virtual = ''
+    @${config.networking.hostName}.${config.networking.domain} ${localUser}
+    ${localUser} ${forwardingAddress}
+  '';
+  config = {
+    inet_interfaces = "loopback-only";
+  };
+};
+```
+
+Emails 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>`).
+
+## Background 
+
+First, 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:
+
+```txt {linenos=table}
+services.postfix = {
+  enable = true;
+  destination = [];
+  domain = config.networking.domain;
+  origin = config.networking.domain;
+  relayHost = config.networking.domain;
+  lookupMX = true;
+  config = {
+    inet_interfaces = "loopback-only";
+  };
+};
+```
+
+However, 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. 
+
+[0]: http://www.postfix.org/STANDARD_CONFIGURATION_README.html#null_client