Need help understanding postfix aliases vs. virtual domains. I want emails to forward to my Gmail account.

February 21, 2015 3.5k views

I do not want to deal with any mail on my server. All I want is for my something like me@allmydomains.tld to forward to me@gmail.com

mydestination vs virtual_alias_domains
I have read probably 10 tutorials and some say to list all my domains under mydestination and others say to list them all under virtual_alias_domains. So which is it?

aliases vs virtual
Again, many tutorials talk about setting up forwarding in the /etc/postfix/aliases file and others talk about doing it in /etc/postfix/virtual so I'm again lost as to which I should be using?

1 Answer

Typically you would only use virtualmailboxdomains etc, if you are hosting more than one domain on the same server. If you are hosting more than one domain use virtual domains, if not then use mydestination. If you are hosting multiple domains the I normally set mydestination to be the FQDN of the server i.e. mailserver.example.tld (as opposed to example.tld for a single domain server). It's probably a good idea to add localhost to your mydestination.

Virtual alias domains do a 1 to 1 mapping of the local part (the bit before the @ symbol in an email address) of the virtual domain to it's target domain but ONLY IF the local part is listed in one of the virtualaliasmaps (you can have none or more maps; separated by commas). These maps (or map) can have various backends; file, hash file, ldap, sql etc.

So in your can you'd probably want to do something like this (a name like <name> can be replaced with anything (don't actually add the angle brackets!));


look inside the file called for the alias mappings

virtualaliasmaps = hash:/etc/postfix/<filename>

virtual-alias.domain anything
me@allmydomains.tld me@gmail.com

The first entry in the virtualaliasmaps file must have the keyword "virtual-alias.domain" in the first entry. The second entry can be anything as it is disregarded.

After that put all the fully qualified aliases and their destination in the first and second entries respectively. Once you have all the entries entered then run

postmap /etc/postfix/

Whatever you do don't put allmydomains.tld (or any of your other virtualaliasdomains) in either the mydestination or relay_domains config entries; it will break.

Have another answer? Share your knowledge.