My task is to create a postfix config that accepts all mail from all domains, recipients, etc. and forwards them to a catchall mailbox. This may be further filtered in future and indeed the config will need to be latered in another environment so that mail goes through to the intended recipient.
Here's an abbreviated main.cf:
....
myhostname = mailserver.fqdn
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination =
myorigin = localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.5.0/24
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = 192.168.5.43, 127.0.0.1
inet_protocols = all
virtual_alias_maps = pcre:/etc/postfix/virtual
virtual_mailbox_base = /var/vmail
virtual_minimum_uid = 2222
virtual_transport = virtual
virtual_uid_maps = static:2222
virtual_gid_maps = static:2222
....
/etc/postfix/virtual:
/.*/ catchall
/catchall\@localhost/ catchall
Other machines are configured to use this mail server as a relayhost, and when mail makes it to here, this appears in the log:
Nov 28 10:08:10 mailserver.fqdn postfix/error[23768]: 5EA9BBD9F5: to=<catchall@localhost>, orig_to=<[email protected]>, relay=none, delay=0, delays=0/0/0/0, dsn=5.1.1, status=bounced (User unknown in virtual alias table)
I'm probably missing something obvious, is it the presence of alias_maps = hash:/etc/aliases
?
Also, if all goes well, can I expect the catchall mailbox to be created automatically, or is there another config item needed?
You can test the outcome with
postmap -q "[email protected]" pcre:/etc/postfix/virtual
. It should returncatchall
. What may happen here is that the/.*/ catchall
also includes thecatchall@localhost
, making it to loop back to itself and eventually not resolved to any real user.If you only have a certain domain and its subdomains, it would be more safe to use:
Then, handle the localhost with
$local_transport
mail delivery transport usingNow, your
catchall@localhost
may be a real local user or an alias defined in/etc/aliases
.Just editing the
/etc/postfix/virtual
file is not enough to make the changes take affect. You must run thepostmap
command to makepostfix
read the file, like so:This creates a new file called
/etc/postfix/virtual.db
and the aliases are now loaded intopostfix
.