I'm using postfix for my email. I know I can use /etc/aliases and newaliases command to redirect certain email, eg I can redirect [email protected] to [email protected] by putting root: user
in my /etc/aliases and then running newaliases
. However I'd like to do the equivilant of *: user
, so that all email to example.com will get sent to [email protected].
How do I do this?
luser_relay = [email protected]
in yourmain.cf
is what you want.To disable user checking and accept all mails you need to add the
local_recipient_maps =
option. DocumentationWhat you are looking for is a virtual alias table and can be done using the following...
First you need to edit, or create if it doesn't already exist, the /etc/postfix/virtual file.
After this has been saved you will need to run
postmap /etc/postfix/virtual
in order to generate the indexed /etc/postfix/virtual.db Postfix will read.You will then need to edit the /etc/postfix/main.cf and be sure that you have the following line uncommented:
This will actually let postfix know about the virtual alias table and use it.
The problem with using the
luser_relay
option as others have mentioned is that this is treated as the user of last resorts for unknown addresses by the local delivery agent. If postfix is only handling mail for one domain this can be utilized for this but it can mask other configuration errors and will likely cause unexpected results if more than one domain is being handled.The one caveat I feel obligated to mention is that by creating a wildcard alias of this nature you are opening up your mail system to accept messages for addresses that will not exist and run the risk of having the mailbox filled quickly with spam for non-existent mailboxes.
It's actually quite simple. All you need to do is to put something like this in your
main.cf
file:The
regexp
part does the trick. Also, in/etc/postfix/virtual_alias
you put something like this:In this example you should receive all mail with destination starting with 'test'. Don't forget to postmap /etc/postfix/virtual_alias and reload postfix.
To combine an answer/comment above that worked easiest for me (I have one primary domain):
Add the following to
/etc/postfix/main.cf
:(
local_recipient_maps =
has no value set)I use a local user linux account and also add same user to /etc/aliases so that user gets all mail to root,postmaster,etc.
Note: luser_relay works only for the Postfix local(8) delivery agent.
For virtuals, you can use
virtual_alias_maps
and point any virtual domain addresses/catchalls at your main email account.Please consult luser_relay or virtual_alias_maps for more info.
If you want to use a catch-all address for mydomain, you can use
/etc/aliases
combined with a regex as follows:In
/etc/postfix/main.cf
addalias_maps = hash:/etc/aliases, regexp:/etc/postfix/catch-all-local.regexp
In
/etc/postfix/catch-all-local.regexp
add!/^owner-/ your-catch-all-user
This should do the trick. It worked for me, and works with virtual_alias_maps set in parallel.
There is a less known static lookup table type in Postfix, which can be used for exactly this purpose:
If [email protected] is not local for this system, you'd also probably want to discard all the bounce messages by replacing lines ending with
bounce
withdiscard
inmaster.cf
to avoid the mail loops.I hate to be a killjoy, but your problem is that you're using Postfix. Postfix makes precisely this exercise very difficult. I know: I had to do it some years ago and it took days and days to get it right. The
luser
option is the right one, but there are other things to get right, too. (And even the name of the option shows that Postfix's authors didn't really want to support this.)I recommend switching to Courier. Courier supports this "catch-all" method in a much more sensible way because of the way it extends its existing alias system.