On my mail server I have an alias from root
to my email address (which is handled by the same server). I also have a content_filter
that uses ${recipient}
. Incoming and outgoing emails work as intended. They get filtered by the content filter with the correct recipient address.
However, when an email is sent to root
from the local machine, the content filter is passed [email protected]
instead of my email address. After processing the email, the filter hands it back to Postfix, then the local delivery forwards it to the right address.
How can I get the alias to be expanded before the content filter is applied?
Current setup
Here is how I currently have the content filter set up (find more details in INSTALL.md):
In
/etc/postfix/master.cf
:gpg-mailgate unix - n n - - pipe flags= user=nobody argv=/usr/local/bin/gpg-mailgate.py ${recipient} 127.0.0.1:10028 inet n - n - 10 smtpd -o content_filter= -o more_options=omitted
In
/etc/postfix/main.cf
:content_filter = gpg-mailgate alias_maps = hash:/etc/aliases local_recipient_maps = $alias_maps $virtual_mailbox_maps proxy:unix:passwd.byname
Other interesting bits
In /etc/aliases
:
root: [email protected]
According to the log, the alias is only expanded in the local delivery agent:
Nov 12 10:45:22 server2 postfix/local[29745]: 0AA16792: to=<[email protected]>, relay=local, delay=0.1, delays=0.05/0.01/0/0.04, dsn=2.0.0, status=sent (forwarded as 19F20A53)
/etc/aliases
declares local aliases and thus is only used by the local delivery. According to ADDRESS_REWRITING_README, only virtual aliases are expanded when mail is received, not local aliases. The solution is to declare virtual aliases. The local aliases can then be removed.