Postfix virtual alias table incorrectly matching regexp rules

I'm setting up a postfix server with virtual alias table to redirect my emails based on regexp rules.

I set this line in /etc/postfix/ :
virtual_alias_maps = regexp:/etc/postfix/virtual

My /etc/postfix/virtual is in the code snippet below.

My goal is to have a list of domains, where :
- all emails sent to tech@thesedomains are forwarded to
- all emails sent to anythingelse@thesedomains (catch-all) are forwarded to

When I test this file with postmap, everything is ok :
# postmap -q regexp:/etc/postfix/virtual
# postmap -q regexp:/etc/postfix/virtual

However, when I apply the config, and send a test email to, the mail is sent to instead.
The log file /var/log/maillog show this :
 XXXXXXXXXXXX: to=<>, orig_to=<>, relay=...

If I remove the last line of the /etc/postfix/virtual, the mails to tech@domains are sent to their correct destination.

According to the manual :
"Patterns are applied in the order as specified in the table,  until  a  pattern  is  found that matches the search string".
So the first matching pattern, and not the second one, should be used (as postmap correctly does).

Any idea why ?

/^domain1\.com$/ DOMAIN
/^domain2\.com$/ DOMAIN

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BenMorelAuthor Commented:
Ok fixed it, needed a 1-1 mapping to stop the recursion :
/^domain1\.com$/ DOMAIN
/^domain2\.com$/ DOMAIN

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.