This question is quite old but I just ran into the same situation having the same environment (postfix; dovecot; mysql) and realised the following approach:
I created a new db table storing my virtual forward configurations:
CREATE TABLE `virtual_forwards` (
`id` int(11) NOT NULL auto_increment,
`domain_id` int(11) NOT NULL,
`source` varchar(100) NOT NULL,
`destination` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
I then created a new virtual forward map file /etc/postfix/mysql-virtual-forward-maps.cf
which queries the previously created virtual_forwards
table AND always returns the concatenated source as well as destination address (mail will be sent to alias AND destination):
user = mailuser
password = <PASS>
hosts = 127.0.0.1
dbname = <DB_NAME>
query = SELECT CONCAT(source, ',', destination) FROM virtual_forwards WHERE source='%s'
And finally I added the new map file to my /etc/postfix/main.cf
as virtual_alias_maps
:
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf,mysql:/etc/postfix/mysql-virtual-forward-maps.cf
Restart your postfix server and everything should work like expected. I favor this approach against adding a comma separated list to the virtual_aliases
table since it just feels wrong for me. But that might be my personal problem :)
I'm aware of the fact that I can't add multiple forwards based on the same source address (e.g. test@tworabbits => test1@tworabbits, test2@tworabbits) but one could easily split the virtual_forwards
table into virtual_forward_sources
AND virtual_forward_destinations
in order to satisfy that requirement.
I hope this helps somebody when another five years have passed :) Cheers!