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 root@my.fqdn.com 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} 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: testing@phunehehe.net

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=<root@server2.phunehehe.net>, relay=local, delay=0.1, delays=0.05/0.01/0/0.04, dsn=2.0.0, status=sent (forwarded as 19F20A53)
  • Usually the method in which the mail is passed to the content filter is defined in the master.cf, what lines do you have that correspond to the content filter? – NickW Nov 11 '13 at 14:08
  • @NickW I added the current setup and link to installation instructions. – phunehehe Nov 11 '13 at 16:32
  • Actually I was expecting to see no_address_mappings as one of the options for receive_overide_options, as unless you set that, aliases and virtual users will be expanded. – NickW Nov 11 '13 at 16:51
  • Wouldn't that prevent aliases from being expanded altogether? As I said, it seems the alias is only expanded in the final delivery step (local) and I want it to happen earlier. – phunehehe Nov 11 '13 at 17:31
  • No, it would specifically stop aliases, etc from being expanded before the content filter sees it (think group aliases, you don't want a single email that goes to twenty people scanned 20 times unless really necessary).. – NickW Nov 11 '13 at 17:35

/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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.