I use postfix as daemon that will accept delivery of mail and process it. Processing mail includes storing it locally so it can be read by a pop3/imap daemon, or forwarding the mail onwards, optionally to multiple recipients.
The official website is at http://www.postfix.org/.
If you want to store mail locally, then these steps must be done first.
Choose a unix user that will keep the mail to be stored locally. I've chosen 'vmail'.
Create the unix user 'vmail'. This is the unix user that has permissions to read and write the mail files that are stored locally.
# useradd vmail
Create the mail storage directory
I've chosen /var/mail/vhosts as my directory. Each user's mail will be stored in their own subdirectory under this directory.
# mkdir /var/mail/vhosts
Change permission on the directory so only the 'vmail' has access to it.
# chown vmail:vmail /var/mail/vhosts
Remember the uid and gid of the 'vmail' user.
# cat /etc/passwd | grep vmail vmail:x:1234:1234::/home/vmail:/bin/sh
In this case the uid and gid is 1234
Edit postfig config /etc/postfix/main.cf
virtual_uid_maps = static:1234 virtual_gid_maps = static:1234 virtual_mailbox_base = /var/mail/vhosts
Make sure the number matches the 'vmail' user uid and gid, otherwise postfix will not have permissions to store the mail.
Make sure virtual_mailbox_base points to your chosen mail storage directory.
virtual_alias_maps = hash:/etc/postfix/virtual
Copy and forwards config will be stored in /etc/postfix/virtual
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
Local mailboxes will be defined in /etc/postfix/vmailbox
Setup DNS so the mail exchanger points to the same server that postfix will be running.
To check that DNS is correct, run
$ nslookup -type=MX example.com Non-authoritative answer: example.com mail exchanger = 300 mail.example.com.
The mail exchanger domain should be where postfix is running.
This is assuming you want to setup email only, and the user does not need a unix login to read their mail.
Edit /etc/postfix/main.cf and add the domain to the list of virtual_mailbox_domains.
Make sure the domain isn't listed in mydestination, this is for normal unix mail.
If you want to have this mail stored locally, so it can be accessed via pop3 or imap, you can add an entry into /etc/postfix/vmailbox.
If your email looks like email@example.com, then add the following line:
Remember to add the trailing slash, so mail is stored in a mailbox format usable by courier-imap.
You can have this mail delivered locally to another existing vmailbox, and forwarded elsewhere. e.g. send a copy to gmail
If you only want to forward the mail to gmail, use something like
firstname.lastname@example.org will have no mail stored locally on the server.
To make the changes take effect, rebuild the configuration. A corresponding file with extension ".db" will appear
Then reload postfix.
# postmap /etc/postfix/vmailbox # postmap /etc/postfix/virtual # postfix reload postfix/postfix-script: refreshing the Postfix mail system
Send an example from an external system to the new email. If you expected mails to be delivered locally, check the directory /var/mail/vhosts/$email_domain/$email_username. In the above example you should be checking that /var/mail/vhosts/example.com/testuser/ has new files appearing.
Check logs at /var/log/mail.log.
See Courier IMAP Setup.