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.

Preliminary information

I will create example.org email domain to locally store milosz@example.org mailbox and relay relay_test1@example.org, relay_test2@example.org to the 1.2.3.4 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.

create_email_domain

Step 2 – Email Mailbox

Add email mailboxes handled locally by the mail server.

create_email_mailbox

Step 3 – Email Routing

Create rules that will relay email only for selected mailboxes.

create_email_routing

Notice that you need to enter email address into the domain field.

create_email_routing_list

Do not add locally stored mailboxes here.

Step 4 – Relay Recipient

Add email addresses for which you permit mail relaying.

create_email_relay_recipient

create_email_relay_recipient_list

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'));

ispconfig_view

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.

ko-fi