Assuming my Postfix server serves the domain example.com, I want it to accept mail for all the subdomains of example.com except for mail.example.com and in.example.com.

At first I've tried using a regular expression that excludes these two subdomains:

(?(?!mail|in).+\.example.com)

But it didn't work. I wasn't sure if the problem is with the regular expression or whether Postfix's regular expression engine doesn't support conditionals, so I've decided to try and use conditionals of the table file. At this point my table looked like this:

/etc/postfix/virtual_domains:

if !/(in|mail)\.example\.com/
/.+\.example\.com/ OK
endif

/etc/postfix/main.cf:

virtual_alias_domains = regexp:/etc/postfix/virtual_domains

But it didn't work either. What am I doing wrong?

link|improve this question

57% accept rate
feedback

2 Answers

up vote 1 down vote accepted

Change this in main.cf:

virtual_alias_domains = !/etc/postfix/not_these_domains.txt regexp:/etc/postfix/virtual_domains

/etc/postfix/not_these_domains.txt:

in.example.com  mail.example.com

And keep /etc/postfix/virtual_domains simple:

/.+@.+\.example\.com/    OK

But note: This only works for Postfix >2.4

link|improve this answer
feedback

If your Postfix is built with PCRE support, try using negative look-behind:

(?<!(mail|in)).+\.example\.com
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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