Postfix + mysql: virtual_users combined with a catch-all in virtual_aliases
By default postfix always lookup in virtual_alias_maps
first. So, it always override the another entry in another maps (for example: alias_maps
and virtual_mailbox_maps
). So we need to exclude email address defined in virtual_mailbox_maps
.
In order to exclude it, we need make new mysql map for virtual_alias_maps
in main.cf
virtual_alias_maps = mysql:/etc/postfix/mailbox.cf, mysql:/etc/postfix/mysql-virtual-alias-maps.cf
Then in mailbox.cf,define query
SELECT email from VIRTUALUSERTABLE WHERE email = %s
That's it. You need query so the result = key lookup. When this happens postfix won't aliasing the email to catchall user.
Reference: postfix tutorial
I found this searching for a similar issue with our system. Adding the mailbox.cf didn't work for us as it bypasses any forwards to mailboxes at the same domain. If you need to forward to mailboxes at the same domain with the catchall in place you need to add the source and destination address to the virtual aliases table.
For example in the question above if you forward [email protected] to [email protected], [email protected] will not see the email. It will only arrive at [email protected]
"More specific aliases have precedence over general catchall aliases." See: https://workaround.org/book/export/html/376
Setup additional forwards like this for same domain rather than adding mailbox.cf:
+----+-----------+------------------------+-------------------------------+
| id | domain_id | source | destination |
+----+-----------+------------------------+-------------------------------+
| 1 | 1 | [email protected] | [email protected] |
| 2 | 1 | [email protected] | [email protected] |
+----+-----------+------------------------+-------------------------------+