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

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

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?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Typically you would only use virtual_mailbox_domains 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 virtual_alias_maps (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 <filename> for the alias mappings

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

/etc/postfix/<filename> virtual-alias.domain anything me@allmydomains.tld

The first entry in the virtual_alias_maps 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/<filename>

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