First Explanation:
/etc/postfix/virtual: This is a plaintext file where you can specify the domains and users to accept mail for. Each virtual domain should begin with a single line containing the domain name. The subsequent lines define addresses at the domain that are deliverable. Mail will be delivered to local usernames on the right side, as demonstrated in the example below. The condition @domain allows you to deliver "all other" mail to the indicated user. You can list multiple domains in this file; just repeat the format demonstrated below. example.com this-text-is-ignored postmaster@example.com postmaster address1@example.com destuser1 address2@example.com destuser2 @example.com destuser1 /etc/postfix/main.cf: virtual_alias_maps = hash:/etc/postfix/virtual Refresh configuration and mappings: postfix reload postmap /etc/postfix/virtual
Second Explanation
Postfix allows you to store virtual alias maps in a text file, which tells postfix how to route virtual email addresses to real users on the system. This setting and the file location is determined in the postfix configuration file /etc/postfix/main.cf
like so:
virtual_alias_maps = hash:/etc/postfix/virtual
The format of the file is with the alias on one side, and the destination on the other, for example like so:
john_smith@example.com john john-smith@example.com john fred@example.com john
This routes all email addressed to john_smith@example.com, john-smith@example.com and fred@example.com to the real user (or system alias) john. It’s possible to have a catch-all alias which will route anything addressed to @example.com to a particular user like so:
@example.com john
If you wanted everything to go to “john” except for mail to fred@ then you can do it like this:
@example.com john fred@example.com fred
Just editing the /etc/postfix/virtual file is not enough to make the changes take affect. You must run the postmap command to make postfix read the file, like so:
/usr/sbin/postmap /etc/postfix/virtual
This creates a new file called /etc/postfix/virtual.db and the aliases are now loaded into postfix.