Setting up an email server is remarkably straightforward, but there are a couple of things to be very careful of so it doesn't end up being a haven for spammers.
An email server consists of several components: an SMTP (Simple Mail Transport Protocol) server to handle mail transfer between hosts, POP and IMAP servers to give users access to mailboxes from their desktop mail clients, and often some kind of mail-filtering system for reducing spam and viruses passing through the system.
There are many SMTP servers available in Ubuntu, and many administrators have their own personal preference, but the Postfix SMTP server is a good general-purpose choice that is fast, secure, and extensible:
sudo apt-get install postfix
The installation process will ask some questions about how the system will operate. Select Internet Site as the operation mode and set Mail Name to your domain.
Once the package has been installed, open /etc/postfix/main.cf in an editor and find a line like:
mynetworks = 127.0.0.0/8
To allow computers on your network to send outgoing email
through the server, you need to add your network range to the
mynetworks value. For example, if your
network is the 192.168.0.0 class-C range, you would edit the line to
mynetworks = 127.0.0.0/8 192.168.0.0/24
This setting is critical to preventing your mail server being used as a relay by spammers, so only add network ranges that you trust.
When mail is delivered to a local user, it ...