I was trying to find a SQL example how to alias email that is addressed to everyone at a secondary domain to my primary domain. I mean:
I have many virtual users set up for example.com, I added a new domain, example-2.com and I want any email going to example-2.com to be delivered to example.com accounts. I don't want to use a catchall like @example-2.com because I want to reject invalid addresses. There are some other virtual domains on the server so the original query still needs to work the same. The virtual_alias_maps table is two columns: addr, dest and of course there may be some addr/dest entries for example.com which should work transparently for example-2.com also I saw some posts saying it should be easy and there are examples, but I can't find the examples. I tried changing my virtual_alias_maps query to something like this: query=(select dest from aliases where addr = '%s') union (select '%u...@example.com' from dual where '%d' = 'example-2.com') limit 1 but it acts the same a having a catchall. So I tried this query=select dest from aliases where (addr = '%s' or ('%d' = 'example-2.com' and addr = '%u...@example.com')) but it only works if there is an alias entry for the address in the table for the address under example.com Maybe the second one is OK but also requires to change my virtual_mailbox_maps to account for the secondary domain? Like this? query=select mail from users where (addr = '%s' or ('%d' = 'example-2.com' and addr = '%u...@example.com')) Even if that works (it does not - the lookups of valid/invalid recipients works better (correctly) but the original address doesn't get rewritten so virtual delivery ultimately fails), is there a way to do it ONLY in the alias map?