First you have to choose if you want info@domain1.com to be a different address vs info@domain2.com: I assume you do, otherwise you wouldn't need Postgresql in the picture.
The second step is to tell Postfix where to find information on domains and email accounts: it looks like you want to use Postgresql instead of a local text file (see http://www.postfix.org/VIRTUAL_README.html#local_vs_database), so you need to:
- create a Postgresql account for Postfix (e.g.
createuser -U postgres --pwprompt postfix
)
- create a postfix_db db
- grant access to the db to user postfix (e.g.
GRANT ALL PRIVILEGES ON DATABASE postfix_db TO postfix_user;
)
create an aliases, users and domains tables:
mail=# CREATE TABLE aliases (
alias text NOT NULL,
email text NOT NULL
);
mail=# CREATE TABLE users (
email text NOT NULL,
password text NOT NULL,
maildir text NOT NULL,
created timestamp with time zone DEFAULT now()
);
mail=# CREATE TABLE domain (
domain varchar(50) NOT NULL,
node varchar(50),
comment varchar(500),
PRIMARY KEY (domain)
);
Finally you need to tell Postfix how to fetch information from these tables (see http://www.postfix.org/PGSQL_README.html). Add to main.cf:
virtual_alias_maps = pgsql:/etc/postfix/virtual_alias_maps.cf
virtual_mailbox_domains = pgsql:/etc/postfix/virtual_mailbox_domains.cf
virtual_mailbox_maps = pgsql:/etc/postfix/virtual_mailbox_maps.cf
The content of virtual_alias_maps.cf will be like this:
user = postfix
password = your-pass
hosts = localhost
dbname = postfix_db
query = SELECT email FROM aliases WHERE alias='%s'
The content of other .cf files will be similar: user, pass, host to connect to the db, name of db and query to fetch the required information.
Postfix will replace the format strings as needed.
This should be enough information to understand how things work from an high perspective.
Once you have a general understanding of what's going on under the hood you can try this gist: https://gist.github.com/solusipse/7ed8e1da104baaee3f05
or this howto: https://github.com/postfixadmin/postfixadmin/blob/master/DOCUMENTS/Postfix-Dovecot-Postgresql-Example.md