It should be achievable - I do something similar but never got round to 'finishing' it off entirely, but I hope this may be of some use to you: (reference to main.cf + standard sql .cf files which will be formed of the generic:
Code:
user = <database_username>
password = <database_password>
dbname = <database_name>
query = {THE QUERY TO GET THE DATA WANTED FOR A MATCH}
hosts = <database_host>
1. Does this server relay for this domain?
relay_domains = proxy:mysql:/etc/postfix/mysql/relay_domains.cf
{query = SELECT domain FROM domains WHERE domain='%s' AND local=0}
Code:
+----+---------------------------------+-------+
| Id | domain | local |
+----+---------------------------------+-------+
2. Does this server relay for this specific recipient
relay_recipient_maps = proxy:mysql:/etc/postfix/mysql/relay_recipients.cf
{query = select virtual_user_email from recipients where alias like '%u\@%d' and local=0}
How is it transported?
3.transport_maps = proxy:mysql:/etc/postfix/mysql/transport.cf
{query = SELECT transport FROM transport WHERE destination='%s'}
Code:
+----+---------------------------------+-----------+
| Id | destination | transport |
+----+---------------------------------+-----------+
| 1 | local.example.com | virtual: |
| 2 | relay.example.com | relay: |
{MORE AT: http://www.postfix.org/transport.5.html}
Go on to define local virtual domains, mailboxes and recipients with:
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql/virtual_domains.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql/virtual_mailbox_recipients.cf
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql/virtual_alias_maps.cf
I mostly had this working when I needed it, the key to making it work was having a 'local' flag in the database that determined if the domain/user was to be dropped locally or relayed on.
You'll probably get better answers from more professional and experiences users than me, but if it falls quite here try joining the postfix users mailing list and ask there {http://www.postfix.org/lists.html}. The users list is a little 'sharp' and be prepared for short, curt answers :-)
HTH