Skip to content

How to forward an e-mail address or a whole domain to /dev/null in Postfix

Last week I wrote about creating a catchall as well as forwarding all incoming e-mails in Postfix (NB: you might want to read that before going on with this post, as I’ll consider here that you already have working e-mail forwarding with the kind of config I used).
Now that I’ve used this to actually replace my Zoho forwarding, it is time to add some basic way to filter spam: I’m talking about not receiving spam to e-mail addresses I know I’ve never ever given as a receiving address. I’ve only got a few, notably do_not_reply/at/, which I put as a sender on all automated e-mails generated from my sites, and yespopupV1@thesame, which I only used as a unique identifier for my Firefox extension Yes Popups. And stupid spammer bots think they are valid… okay, they were right… until now 😉

So, to stop receiving e-mails on those addresses, all I had to do was forward them to /dev/null. The problem is, it’s not possible put something like: /dev/null
in the Postfix alias file (/etc/postfix/virtual)

Instead, you have to create a system-wide alias, and then forward e-mails to it. So:
nano /etc/aliases
Then add a line such as:
devnull: /dev/null
(NB: you can chose whatever name you want instead of “devnull”, but I think that’s the most obvious and convenient one)
Then apply the changes (don’t forget that part or e-mails will bounce until you restart!):

Now, you just need to configure Postfix to forward e-mails to user devnull. See the post I mentioned at the very beginning for details, long story short and considering that you already have some e-mail forwarding in place like my configuration:
nano /etc/postfix/virtual
add a line like: devnull
then apply:
postmap /etc/postfix/virtual
postfix reload

That’s all already. Don’t forget to test your setup though…

Additional note: if for some reason you have trouble setting-up system-wide aliases, as an alternative you can just use Webmin to create a user “devnull” with custom shell “/dev/null”. I tried it too, it seems to work just as well.


Posted in Linux, postfix, servers.

One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

or, reply to this post via trackback.

Sorry about the CAPTCHA that requires JS. If you really don't want to enable JS and still want to comment, you can send me your comment via e-mail and I'll post it for you.

Please solve the CAPTCHA below in order to fight spamWordPress CAPTCHA