I hit an intriguing problem as I needed to relay selected mailboxes rather than the whole domain. I assume that you have already noticed that everything needs to happen on the same domain. It is rare and quite interesting task so I will quickly describe it here using ISPConfig 3 but beware as this is a very specific topic so I strongly suggest to investigate it further before applying any changes.
I will create example.org email domain to locally store firstname.lastname@example.org mailbox and relay email@example.com, firstname.lastname@example.org to the 220.127.116.11 server.
I will use ISPConfig 3 on CentOS as this is an easiest way to explain this idea.
Step 1 – Email Domain
Login to ISPConfig 3 and create email domain.
Step 2 – Email Mailbox
Add email mailboxes handled locally by the mail server.
Step 3 – Email Routing
Create rules that will relay email only for selected mailboxes.
Notice that you need to enter email address into the domain field.
Do not add locally stored mailboxes here.
Step 4 – Relay Recipient
Add email addresses for which you permit mail relaying.
Step 5 – Database
Open dbispconfig database and create new view which will be used in the next step.
CREATE VIEW my_virtual_mailboxes AS SELECT u.email AS email FROM mail_user AS u WHERE ((u.postfix = 'y') AND (u.server_id = '1')) UNION SELECT r.source AS email FROM mail_relay_recipient AS r WHERE ((r.active = 'y') AND (r.server_id = '1'));
This is an important part because postfix needs to accept email to the locally stored mailboxes and strictly permitted addresses before relaying them.
Step 6 – Postfix
Change virtual mailboxes table name to the recently created view.
$ cat /etc/postfix/mysql-virtual_mailboxes.cf
user = ispconfig password = ... dbname = dbispconfig #table = mail_user table = my_virtual_mailboxes select_field = CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/') where_field = email additional_conditions = hosts = 127.0.0.1
This is an quite easy solution for this specific problem although you don’t need to install ISPConfig to achieve it. Just set up small machine in lab and modify postfix configuration by hand. It will require a bit of further reading but you already have all necessary information.