Postfix will allow you to deliver emails to different domains, and to send emails. You should install something like Dovecot or Courier to handle the pop/IMAP.
Read the Ubuntu documentation for postfix here. Important things to pay attention to are the type of inbox (maildir vs mbox) and your authentication (Dovecot SASL vs Cyrus SASL; flat file vs sql db).
You'll want to use the Postfix virtual mailbox delivery agent to deliver mail from separate domains to non-system accounts. Here is an example configuration to add to your main.cf file (/etc/postfix/main.cf) for the domain "example.com":
virtual_mailbox_domains = example.com ...more domains...
virtual_mailbox_base = /var/mail/vhosts
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_minimum_uid = 100
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_alias_maps = hash:/etc/postfix/virtual
In the third line there's virtual_mailbox_maps =
. This is the file that holds the mapping between the email address and where the email is stored. You'll need to add the following to your vmailbox file (/etc/postfix/vmailbox):
[email protected] example.com/info
[email protected] example.com/sales/
# Comment out the entry below to implement a catch-all.
# @example.com example.com/catchall
...virtual mailboxes for more domains...
In the seventh line of main.cf there's a line with virtual_alias_maps =
that maps the alias names you might use. Add the following to your virtual file (/etc/postfix/virtual):
[email protected] postmaster