Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to configure postfix to put incoming mails from different domains to respective catchall mailboxes.

Use case is the following:

  • enterprise customers send emails to the address (local part is always different, the domain part is always the same for all customers)
  • the destination mailbox, where the mail is placed must be equal to the sender domain (emails from and are placed in the / , mails from in /
  • the mailboxes / and / are polled via POP3 by different clients with different authentication credentials

Example, the following incoming mail:


should be placed in the local virtual mailbox:


The To-domain is always the same. The local mailboxes are all named as possible incoming From-domains.

Is there a possibility to use virtual_mailbox_maps or similar for this purpose?


I have created following entry in /etc/postfix/virtual_alias_maps:       catchall

to point all mails to the mailbox "catchall".

In this mailbox i have created a Sieve script /var/mail/vhosts/

require ["variables"];

# pick any ("*") domain in From or Sender header
if address :matches :domain ["From", "Sender"] "*" {
        #  the variable ${1} contains the domain name
        redirect "${1}";

This Sieve script redirects all mails to the mailbox equals to sender domain (e.g.

To reject all mails from not known (not in the database) domains, used smtpd_sender_restrictions in /etc/postfix/

smtpd_sender_restrictions =  permit_mynetworks, pgsql:/etc/postfix/


user = dbuser
password = dbpass
dbname = customers
query = select case count(*) when 0 then 'REJECT' else 'OK' end from servers where user_domain='%d';
hosts =
share|improve this question
Oh, you updated the question. I will take a further look when time permits... – cstamas Nov 28 '12 at 9:18
i have updated, in the same time, you have answered, so i did not noticed it first. your answer make sence and i'm tring to implement your suggestion with Dovecot ( Pigeonhole, Sieve filtering rule). I will report my success (or fail). – DronNick Nov 28 '12 at 13:45
up vote 1 down vote accepted

This is not the MTA's job. It is better to do this in the MUA (your client program).

If you really want to do this on the server side choose some mail filtering program like dovecot (it is sieve compatible) or maildrop (has its own proprietary filtering solution). (procmail is also available, but I would not recommend that one).

There is a howto for Maildrop configuration How to set up filters:

share|improve this answer
Thanks for directing me to the solution! – DronNick Dec 13 '12 at 14:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.