rohx
rohx

Reputation: 43

configure catch-all alias in postfix using mysql

It seems like my catch-all alias doesn't work. When I use

postmap -q [email protected] mysql:/etc/postfix/mysql-virtual-alias-maps.cf

There is no output. But when I command

 postmap -q [email protected] mysql:/etc/postfix/mysql-virtual-alias-maps.cf

the output is

 [email protected]. 

How can I fix this?

The configure query is:

query= SELECT destination FROM virtual_aliases WHERE source='%s'

Table virtual_aliases:

id  domain_id   source             destination
5   1           @example.org        [email protected]
7   1           [email protected]    [email protected]
8   1           [email protected]    [email protected]

Table virtual_domains:

id  name
1   example.org

Table virtual_users:

id  domain_id   password    email
1   1           pwd         [email protected]

Upvotes: 4

Views: 2300

Answers (2)

slf
slf

Reputation: 22777

@clement is correct but there is a simpler query that would work that is easier on the sql server. Here is what worked for me:

Changed query line in /etc/postfix/mysql-virtual-alias-maps.cf

query = select distinct destination from virtual_aliases where source='%s' or source = '@%d';

Upvotes: 0

clement
clement

Reputation: 3375

Your mysql query should be

SELECT destination FROM virtual_aliases WHERE source='%s' 
UNION ALL  
SELECT destination FROM virtual_aliases WHERE source='@%d' 
AND NOT EXISTS (SELECT destination FROM virtual_aliases WHERE source='%s')

Upvotes: 6

Related Questions