Silently drop emails to specific invalid domain?

Justin Lloyd asked:

What is the best way to have Postfix silently drop emails to a specific invalid domain?

For reasons that cannot be handled otherwise right now, our mail servers receive a lot of emails for addresses of form $userid@BLAH, where @BLAH is always that value and $userid is programmatically-generated by the sender. The sender mail servers are allowed to relay through our mail servers but since BLAH is not a valid domain, the messages get deferred with “Host or domain name not found. Name service error for name=BLAH type=MX: Host not found, try again”. Obviously header_checks doesn’t work since that’s handled well after the hostname lookup.

I’d like to prevent these from ever getting to the queue, even though they do eventually age out after a few retries, and just silently discard them instead. (Eventually we’ll get the source issue resolved but that may not be any time soon.)

My answer:

First, you’ll need to accept mail for the nonexistent domain, e.g. by adding it to virtual_mailbox_domains.

Then you’ll need to make a catchall address in virtual_mailbox_maps that delivers it locally, for example:    throwaway

Last you need to make a local alias for throwaway in /etc/aliases that delivers mail to /dev/null, e.g.:

throwaway       /dev/null

Postmap and reload postfix as appropriate.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.