I just made it through this helpful article and successfully have my mail server set up with a single domain.

What I'm wondering now is how I can be able to add multiple email account for different domains.

To add a new email account currently, I would use the command:

useradd -m john -s /sbin/nologin

That would allow me to have an email that looks something like john@example.com.

What would I do if I wanted multiple domains? (like john@example2.com)

Thanks, I'm still completely new to the world of VPS:)


You would use a virtual_map to map virtual users in your second domain to either real users on the server or to other addresses (similar to an alias).

e.g. in /etc/postfix/main.cf you would have:

virtual_maps = hash:/etc/postfix/virtual

and in /etc/postfix/virtual:

example.com            VIRTUAL

john@example.com       john@myrealdomain.example.com
joe@example.com        joe@somewhere.else.example.com

# catch-all (optional and not recommended as it can act as a spam amplifier)
@example.com           john@myrealdomain.example.com

example2.com           VIRTUAL
john@example2.com      john@yet.another.example.com
fred@example2.com      fred@somewhere.else.again.example.com
@example2.com          someuser@myrealdomain.example.com

Remember to run postmap /etc/postfix/virtual after editing it. And postfix reload after editing /etc/postfix/main.cf

See man 5 virtual for more details about the postfix virtual table format.

  • Awesome! How would the useradd command differ when adding a user for a specific email address?
    – Doug Beney
    Nov 10 '15 at 1:09
  • They're virtual users - you wouldn't use useradd unless you needed to make a local user to deliver some or all of the virtual users' mail to.
    – cas
    Nov 10 '15 at 1:25
  • Gotcha. So when I add this to my email client, would the password still be the same as the initial 'john' user that I created with the useradd command?
    – Doug Beney
    Nov 10 '15 at 1:57
  • if that's the account you forward the mail to with the virtual table, then yes.
    – cas
    Nov 10 '15 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.