1

I have a problem with my configuration of postfix. I wanted to set up a catch-all email address for a domain. I have my virtual mailboxes and aliases saved in a postgresql database. Queries defined in files vdomains.cf, vmailbox.cf and valias.cf are these, respectively:

query = SELECT 1 FROM domains WHERE domain = '%s'

query = SELECT CONCAT(domains.domain, '/', mailboxes.address, '/') AS maildir FROM mailboxes LEFT JOIN domains ON mailboxes.domain = domains.id WHERE mailbox='%s'

query = SELECT dst FROM virtual_aliases WHERE src = '%s'

Those files are linked to main.cf by this block

virtual_mailbox_domains = pgsql:/etc/postfix/vdomains.cf
virtual_alias_maps = pgsql:/etc/postfix/valias.cf
virtual_mailbox_base = /srv/mail
virtual_mailbox_maps = pgsql:/etc/postfix/vmailbox.cf
virtual_uid_maps = pgsql:/etc/postfix/vuidmaps.cf
virtual_gid_maps = pgsql:/etc/postfix/vdomainmaps.cf
virtual_transport = lmtp:unix:private/dovecot-lmtp

This works perfectly for known recipients and server rejects all unknown recipients. Aliasing also works, if I define one address in the alias table mapping to another existing address in the mailbox table.

The problem is that the alias table gets resolved before the mailbox table, which creates a big problem when I want to alias a catch-all email like this:

src          dst
@domain.com  catchall@domain.com

This gets resolved before the actual mailbox and therefore all emails, including those intended for existing users, are forwarded to the catchall@domain.com address.

According to several answers here on stack or other sites, this setup should work and probably does for some people, so I believe that I am doing something wrong.

Last thing - my setup is Debian Jessie with Postfix 2.11.3.

Any help is much appreciated, thanks in advance

j0hny
  • 175
  • 1
  • 2
  • 9

1 Answers1

0

I have finally found a solution. It is probably not the best one, but I was unable to find a more correct one, having read all of the relevant postfix documentation and numerous other posts. This question not being answered is another indicator that a "correct" solution might not exist.

My workaround is pretty simple. I have found out that if you specify all the existing addresses in the virtual aliases table like this:

test@testdomain.com    test@testdomain.com
test2@testdomain.com   test2@testdomain.com

(basicly the same source and destination)

it works as expected by the original intent. (this was a suggestion I found in another question regarding the same subject). Well, putting this information into the virtual_aliases table is clearly wrong (duplication of information, ...), so I came up with a more elegant solution:

CREATE OR REPLACE VIEW v_virtual_aliases AS 
 SELECT mailboxes.mailbox AS src,
    mailboxes.mailbox AS dst
   FROM mailboxes
UNION ALL
 SELECT virtual_aliases.src,
    virtual_aliases.dst
   FROM virtual_aliases;

What this does is simply create a view with all the information from the virtual_aliases table combined with all the existing mailboxes from the actual mailboxes table. This way no data are duplicated and aliasing works as expected - only for addresses that do not have an entry in mailboxes table. Given this query, performance should not be a problem even for large databases.

I then updated the valias.cf file accordingly:

query = SELECT dst FROM virtual_aliases WHERE src = '%s'

Now everything works as expected by the original question.

j0hny
  • 175
  • 1
  • 2
  • 9