jump to navigation

Postfix & catchall domains with exceptions 2009 May 4 19:22

Posted by diamond in : Random , trackback

So, you have a domain (we’ll use catch.example as a, uh, example). You’d like most addresses at that domain (foo@catch.example, bar@catch.example, and so on) to get send to your actual email account (bob@real.example). However, you’d also like to be able to selectively drop mail to certain addresses (bad@catch.example and unwanted@catch.example). Finally, you’d like to do this using postfix. Well, here’s how.

  1. Setup postfix to handle mail for catch.example (Note: getting mail for catch.example to be delivered to your server in the first place is beyond the scope of this) by adding these lines to /etc/postfix/main.cf:
    # Aliases for virtually hosted domains
    virtual_alias_domains = catch.example
    virtual_alias_maps = hash:/etc/postfix/virtual.aliases
  2. Create /etc/postfix/virtual.aliases mapping file that tells postfix what to do with mails for the catch.example domain with these contents:
    @catch.example bob@real.example
    bad@catch.example null
    unwanted@catch.example null

    Note: there should be no : between the two entries on each line, this is not the /etc/aliases file format.
  3. Add a null alias to your /etc/aliases file:
    null: /dev/null
  4. Update the mapping and alias database files, and reload postfix’s configuration:
    postmap /etc/postfix/virtual.aliases
    postalias /etc/aliases
    postfix reload

And that’s it. Any mail to catch.example that’s not to one of the specified unwanted email addresses will be forwarded to your real email account, and the rest will be silently dropped. Voila.

***Update***
Actually, i’ve just noticed that if you want more control over what happens to the exceptions, you can use check_recipient_access, which allows you to specify desired actions such as accept, reject, discard etc. That said, i’d be a lot more wary about using check_recipient_access as its extra power includes more own-foot-removal capabilities.

Comments»

no comments yet - be the first?