When your Postfix forwards a message — alice@example.com aliases to alice.smith@gmail.com — and Postfix sends it onward, the envelope sender is still the original sender at the original domain. Gmail checks SPF against the forwarding IP and the original domain’s SPF record; the record doesn’t list your IP, so SPF fails. SRS (Sender Rewriting Scheme, RFC 7505 background) is the universally adopted workaround: rewrite the envelope sender at forwarding time to a reversible address at your domain, so SPF passes for your domain, and the bounce can still be routed back to the original sender. This article is the PostSRSd install we apply to every forwarder we run.
How to verify
Audit the current forwarding posture.
sudo postconf | grep -E 'sender_canonical|recipient_canonical|smtp_generic'
dpkg -l | grep postsrsd
systemctl is-active postsrsd 2>/dev/null
echo "test" | mail -s "srs probe" some-alice@example.com # an alias that forwards out
sudo journalctl -u postfix | grep alice | tail -10
You’re looking for the from= field in the log when the forward fires. If it reads the original external sender (from=external-user@somewhere.com), SPF will fail at the next hop. If it reads a rewritten address at your domain (from=SRS0=xxx=yy=somewhere.com=external-user@example.com), SRS is doing its job.
What’s happening
The forwarding problem in detail:
external-user@somewhere.comsends mail toalice@example.com.- Postfix at
mx1.example.comaccepts, looks upaliceinvirtual_alias_maps, sees the alias goes toalice.smith@gmail.com. - Postfix sends the message to Gmail with
MAIL FROM: external-user@somewhere.comand the original headers. - Gmail checks SPF. The record at
somewhere.comlistssomewhere.com’s mail servers — not your203.0.113.10. SPF returnsfail. - With DMARC
p=quarantineorp=rejectatsomewhere.com, Gmail drops the message.
SRS rewrites step 3:
- The envelope sender becomes
SRS0=secret_hash=timestamp=somewhere.com=external-user@example.com. - SPF check at Gmail now evaluates
example.com’s SPF record against your IP — which lists you correctly. - If Gmail bounces, the bounce arrives back at
MAIL FROM, which is atexample.comand reversible — Postfix decodes the SRS address back toexternal-user@somewhere.comand forwards the bounce there.
The “secret” in the encoded address is an HMAC keyed with a local secret, so attackers can’t forge SRS addresses for spoofed bounces.
The procedure
-
Install PostSRSd. It’s a small C daemon that exposes a Postfix policy daemon socket on TCP:
sudo apt update sudo apt install -y postsrsd sudo systemctl status postsrsd --no-pager ss -ltnp | grep -E ':(10001|10002)\b'PostSRSd listens on two ports — 10001 for sender rewriting (outbound), 10002 for sender unrewriting (inbound bounces).
-
Configure the local domain and secret. Edit
/etc/default/postsrsd:SRS_DOMAIN=example.com SRS_EXCLUDE_DOMAINS=example.com,partner.com SRS_SECRET=/etc/postsrsd.secret SRS_HASHLENGTH=4 SRS_HASHMIN=4 SRS_FORWARD_PORT=10001 SRS_REVERSE_PORT=10002The secret file is auto-generated on first start if missing:
sudo ls -l /etc/postsrsd.secret # -rw------- 1 postsrsd postsrsd 32 ...SRS_EXCLUDE_DOMAINSlists local domains you do NOT want rewritten — mail you originate yourself shouldn’t be SRS-encoded. -
Wire Postfix to PostSRSd. Add to
/etc/postfix/main.cf:# Forward-direction rewriting (outbound) sender_canonical_maps = tcp:127.0.0.1:10001 sender_canonical_classes = envelope_sender # Reverse-direction unrewriting (inbound bounces) recipient_canonical_maps = tcp:127.0.0.1:10002 recipient_canonical_classes = envelope_recipient, header_recipientsender_canonical_classes = envelope_sendermeans Postfix only rewrites the envelope MAIL FROM, not theFrom:header. TheFrom:stays the original — clients see who really sent it. -
Restart both daemons and verify:
sudo systemctl restart postsrsd sudo postfix check sudo systemctl reload postfix sudo journalctl -u postsrsd -n 20 --no-pager -
Send a probe through an external→alias→external chain. From an external sender (a mailbox you control on Gmail), send to
alice@example.comwhich aliases to a second external mailbox you control:# From your laptop, with Gmail's SMTP or any external swaks --to alice@example.com --from real-you@gmail.comThen check the headers of the delivered message at the second mailbox — the
Return-Path:andReceived-SPF:lines should referenceSRS0=...@example.com, and the SPF check at the receiver should pass. -
Confirm the bounce path works. Send a probe to a recipient you know is a hard bounce (use a known dead address, or a special
bounce@simulator.amazonses.comif you have SES):swaks --to dead-address@somewhere.com --from real-you@gmail.com --server mx1.example.comThe bounce that comes back addressed to
SRS0=hash=ts=gmail.com=real-you@example.comshould be unwrapped by PostSRSd’s reverse port and routed back toreal-you@gmail.com. Tail the log to confirm.
Operational notes
- The SRS secret is the cryptographic key that prevents bounce forgery. Treat it like a database password — back it up, rotate annually, store in your secrets manager.
- The
SRS_HASHLENGTH=4means 4 base32 characters of HMAC — about 20 bits. Enough to defeat casual forgery; not enough to defeat a determined attacker. Bump to 6 or 8 for high-value forwarders. - SRS-encoded addresses look weird (long, base32, equal-sign-laden) and some legacy spam filters score them as suspicious. We have seen ~1% of messages get a small DMARC score increase from this. Acceptable trade-off.
- Without SRS, every legitimate forwarded message from a DMARC-enforcing domain (Google Workspace, Microsoft 365, banks) silently disappears. The fix is non-optional in 2026.
- SRS is incompatible with some receivers’ DMARC reporting because the rewritten envelope confuses ARC. ARC (Authenticated Received Chain, RFC 8617) is the long-term solution; PostSRSd is a pragmatic interim until ARC is ubiquitous.
Common pitfalls
- PostSRSd is started before its secret file is generated; both subsequent restarts produce different addresses, making old bounces undecodable. Once a secret is in place, do not regenerate without coordinated cutover.
sender_canonical_classesdefaults toenvelope_sender, header_sender— leavingheader_senderin the list rewrites theFrom:header too, which breaks DKIM signatures on the upstream message. Restrict toenvelope_senderonly.- The
SRS_EXCLUDE_DOMAINSlist omits a local domain, and your own outbound mail gets SRS-encoded — receivers see weird envelope senders for routine company mail. Include every local virtual domain in the exclude list. - A forwarded message bounces back, the bounce hits the reverse port, but
recipient_canonical_mapswas set withtcp:127.0.0.1:10001(forward port by mistake) — bounces stay encoded and double-bounce out. - PostSRSd listens only on localhost by default; a hardened deployment leaves this and uses unix-socket Postfix integration. Don’t expose the SRS ports outside the host.
Stack Harbor stands up PostSRSd on every Postfix that forwards mail in the engagements we run — secret stored in a managed vault, exclude list pinned to the tenant’s known domains, and the reverse path verified by a deliberate bounce probe before declaring the forward complete. If you have a Postfix that aliases mail and customers report missing messages, that audit is part of our Managed Operations practice.