PHORGE_INBOUND.md (2917B)
1 # Phorge Inbound Email 2 3 Documents the inbound email setup for Phorge at https://phorge.mtrnord.blog. 4 5 ## How it works 6 7 Phorge generates reply-to addresses like `phorge+T123+hash@phorge.mtrnord.blog`. When a user 8 replies to a Phorge notification, the reply flows: 9 10 ``` 11 Reply email → MX phorge.mtrnord.blog → email-gateway LB (cluster) 12 ↓ 13 Stalwart (relay rule for phorge.mtrnord.blog) 14 ↓ relays via Hetzner private network 15 Postfix on dns-a (10.0.64.129:25) 16 ↓ virtual alias → pipe 17 /var/www/html/git/phorge/scripts/mail/mail_handler.php 18 ↓ 19 Phorge DB — comment created 20 ``` 21 22 ## Cluster config (gitops) 23 24 Stalwart routes all mail for `phorge.mtrnord.blog` to `10.0.64.129:25` via a relay rule in 25 `apps/talos_cluster/stalwart/release.yaml`: 26 27 ```yaml 28 queue: 29 route: 30 phorge-relay: 31 type: relay 32 address: 10.0.64.129 33 port: 25 34 protocol: smtp 35 tls: 36 implicit: false 37 allow-invalid-certs: true 38 strategy: 39 route: 40 - if: "rcpt_domain == 'phorge.mtrnord.blog'" 41 then: "'phorge-relay'" 42 ``` 43 44 ## dns-a config (10.0.64.129) 45 46 Postfix accepts mail for `phorge.mtrnord.blog` and pipes it to `mail_handler.php`. 47 48 **`/etc/postfix/main.cf` relevant settings:** 49 50 ``` 51 mydestination = localhost 52 virtual_alias_domains = phorge.mtrnord.blog 53 virtual_alias_maps = hash:/etc/postfix/virtual 54 mynetworks = 127.0.0.0/8 10.0.64.0/19 55 smtpd_relay_restrictions = permit_mynetworks, reject 56 smtpd_recipient_restrictions = permit_mynetworks, reject 57 inet_interfaces = 127.0.0.1, 10.0.64.129 58 inet_protocols = ipv4 59 ``` 60 61 **`/etc/postfix/virtual`:** 62 63 ``` 64 phorge@phorge.mtrnord.blog phorge-pipe 65 ``` 66 67 **`/etc/aliases`:** 68 69 ``` 70 phorge-pipe: "|/var/www/html/git/phorge/scripts/mail/mail_handler.php" 71 ``` 72 73 **Phorge config:** 74 75 ``` 76 metamta.reply-handler-domain = phorge.mtrnord.blog 77 metamta.single-reply-handler-prefix = phorge 78 ``` 79 80 ## DNS 81 82 ``` 83 phorge.mtrnord.blog. MX 10 <email-gateway-lb-ip> 84 phorge.mtrnord.blog. TXT "v=spf1 mx include:midnightthoughts.space ~all" 85 ``` 86 87 ## Troubleshooting 88 89 **Test the pipe directly on dns-a:** 90 91 ```bash 92 echo "From: test@example.com 93 To: phorge@phorge.mtrnord.blog 94 Subject: Test 95 Message-ID: <test-$(date +%s)@example.com> 96 97 test body" | sudo /var/www/html/git/phorge/scripts/mail/mail_handler.php 98 ``` 99 100 **Check Phorge received it:** 101 102 ```bash 103 cd /var/www/html/git/phorge && ./bin/mail list-inbound 104 ``` 105 106 **Check Postfix queue on dns-a:** 107 108 ```bash 109 sudo mailq 110 sudo postcat -q <queue-id> 111 ``` 112 113 **Check Stalwart relay delivery in pod logs:** 114 115 ```bash 116 kubectl logs -n stalwart -l app.kubernetes.io/name=stalwart-mail | grep phorge 117 ```