postfix - how do you redirect all emails to one user, eg *@example.com → [email protected]

Solution 1:

luser_relay = [email protected] in your main.cf is what you want.

To disable user checking and accept all mails you need to add the local_recipient_maps = option. Documentation

Solution 2:

What 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.

example.com   whatever
@example.com  [email protected]

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:

virtual_alias_maps = hash:/etc/postfix/virtual

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.


Solution 3:

It's actually quite simple. All you need to do is to put something like this in your main.cf file:

virtual_alias_maps = regexp:/etc/postfix/virtual_alias

The regexp part does the trick. Also, in /etc/postfix/virtual_alias you put something like this:

/^test/ [email protected]

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.


Solution 4:

To combine an answer/comment above that worked easiest for me (I have one primary domain):
Add the following to /etc/postfix/main.cf :

luser_relay = [email protected] (or local system user)
local_recipient_maps =

(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.

You can also combine this same address in your virtual_alias_maps and point any virtual domain catchalls at this same primary account.

Please consult luser_relay for more.


Solution 5:

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 add
alias_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.

Tags:

Email

Postfix