Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have set up a header filter in postfix to discard messages from Russia and Romania because of the volume of spam coming from those and we do not currently do business in those countries.

My regex looks like this

/^From:.*\@.*\.ro/     DISCARD

Problem is it is discarding messages containing .rodomainsomething like

How would I make it filter exact to TLD .ro?


share|improve this question
You're doing spam filtering wrong if you're doing it this way. Something like SpamAssassin (or a commercial service like Postini) is a much better and more reliable choice... – voretaq7 Dec 12 '12 at 2:06
Thanks but I would like an answer about how to form the regex so that it only filters the TLD. I have spamassasin running. I want postfix to discard the message before it gets scanned. – Jesse Cain Dec 12 '12 at 14:08
up vote 0 down vote accepted

This is the regexp you need:

/^From:.*\@.*\.ro$/ REJECT

OTOH: I agree with the others that other solutions like content filtering are much better for this.

share|improve this answer
  1. You should really use a spam filter like Spamassassin for this.
  2. You should probably use REJECT instead of DISCARD.
  3. Like any computer program a regex will do what you say, not what you mean. To match a word boundary include it in the regex, e.g.: /\@.*\.ro\b/
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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