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 [email protected] (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 [email protected] and [email protected] are placed in the /customer1.com , mails from [email protected] 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: [email protected]
To: [email protected]
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