Link to home
Start Free TrialLog in
Avatar of BenMorel
BenMorel

asked on

Postfix virtual alias table incorrectly matching regexp rules

Hi,
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/main.cf :
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 email1@otherdomain.com
- all emails sent to anythingelse@thesedomains (catch-all) are forwarded to email2@otherdomain.com.

When I test this file with postmap, everything is ok :
# postmap -q tech@domain1.com regexp:/etc/postfix/virtual
email1@otherdomain.com
# postmap -q anything@domain1.com regexp:/etc/postfix/virtual
email2@otherdomain.com

However, when I apply the config, and send a test email to tech@domain1.com, the mail is sent to email2@otherdomain.com instead.
The log file /var/log/maillog show this :
 XXXXXXXXXXXX: to=<email2@otherdomain.com>, orig_to=<tech@domain1.com>, 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 ?

Thanks.
Ben
/^domain1\.com$/ DOMAIN
/^domain2\.com$/ DOMAIN
 
/^tech@/      email1@otherdomain.com
/@/           email2@otherdomain.com

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of BenMorel
BenMorel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial