6

I have a Postfix (and Dovecot) server running, using MySQL to define the domain names, users and aliases. This is all running fine, but now I want to add a catch-all to a domain where I already have some users defined for. I added the user in the virtual_users table, and while I can connect to it and send emails with it, all the emails that are sent to it are being captured by the catch-all. Is there a way to solve this?

Relevant configuration files and details:

/etc/postfix/main.cf:

virtual_transport = lmtp:unix:private/dovecot-lmtp  
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf  
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf  
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf  
local_recipient_maps = $virtual_mailbox_maps  

mysql virtual users table:

+----+-----------+--------------+------------------------+  
| id | domain_id | password     | email                  |  
+----+-----------+--------------+------------------------+  
|  2 |         1 | passwordhash | [email protected] |  
+----+-----------+--------------+------------------------+  

mysql virtual aliases table:

+----+-----------+------------------------+-------------------------------+  
| id | domain_id | source                 | destination                   |  
+----+-----------+------------------------+-------------------------------+  
|  2 |         1 | @example.com           | [email protected]   |  
+----+-----------+------------------------+-------------------------------+  

2 Answers 2

11

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

2
1

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]        |  
+----+-----------+------------------------+-------------------------------+  
1
  • 2
    please do not use domain.com as an example domain name, this domains is owned by someone. Please use example.com as it is described in RFC 2602 Reserved Top Level DNS Names tools.ietf.org/html/rfc2606 Sep 25, 2015 at 10:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .