Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 123@myservice.com (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 foo@customer1.com and bar@customer1.com are placed in the /customer1.com , mails from baz@customer2.com in /customer2.com)
  • the mailboxes /customer1.com and /customer2.com are polled via POP3 by different clients with different authentication credentials

Example, the following incoming mail:

From: foo@customer1.com
To: 123@myservice.com

should be placed in the local virtual mailbox:

/customer1.com

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?

UPDATE:

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

@myservice.com       catchall

to point all mails to the mailbox "catchall".

In this mailbox i have created a Sieve script /var/mail/vhosts/myservice.com/catchall/.dovecot.sieve:

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. customer1.com).

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

smtpd_sender_restrictions =  permit_mynetworks, pgsql:/etc/postfix/pgsql_check_sender_access.cf

/etc/postfix/pgsql_check_sender_access.cf:

user = dbuser
password = dbpass
dbname = customers
query = select case count(*) when 0 then 'REJECT' else 'OK' end from servers where user_domain='%d';
hosts = 127.0.0.1:5432
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
add comment

1 Answer

up vote 0 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 http://www.postfix.org/MAILDROP_README.html How to set up filters: http://www.courier-mta.org/maildropex.html

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

Your Answer

 
discard

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.