Linux is all about choice, flexibility and configurability. There are a myriad of options when it comes to setting up a Mail Server. It can be taylored to service a home network with a few mail users, or a large corporation handling thousands of messages a day. However, this flexibility makes the task for the uninitiated all the more difficult, it's easy to get bogged down in the details. The aim of this howto is to discuss the basic processes and programs involved as well as some of the terminology.
These are the steps you need to follow to set up a basic Mail Server:
The central core of a Mail Server is the Mail Transfer Agent (MTA). This is the program that handles the scheduling, sorting and delivery of incoming and outgoing mail. The most commonly used MTAs are Sendmail, Postfix, qmail and Exim. The Sendmail program is the original and venerable MTA that is still widely used. Sendmail, however, has a reputation as being difficult to configure, and the other three are mooted as easier-to-use and faster alternatives. Edit the MTA's configuration file to suit, and start the service.
An MTA uses the Simple Mail Transfer Protocol (SMTP). This is the standard protocol used to move email over the internet.
Email had its origins on Unix systems. Unix (and of course Linux) is a multi-user operating system and traditionally an email account is synonynous with a user account. When the MTA receives an email for the user, it puts it in a file in a directory assigned to that user. The simplest way to set up a Mail Server is in traditional Unix fashion, just add a new user and the email account is automatic. For the most part, this approach works fine and is the default mode of operation for all of the mentioned MTAs except qmail.
Problems can arise if your MTA serves mail for more than one domain, and you want the same user name in both domains. A user isn't attached to a domain, so if you have joe@mydomain.com and joe@example.com, two different mail accounts, you have a problem because you can only have one user 'joe'. The solution is to abandon the traditional approach and use a database for user account information and mailboxes. All of the main MTAs can be configured to do so. This is refered to as using virtual hosts. It should be noted that multiple domains can still be used without the need to set up databases and virtual hosts. This howto will limit itself to discussing this simpler method.
The MTA delivers mail to a user mailbox. POP and IMAP servers fetch mail from the mailbox when requested to by a Mail User Agent (MUA). An MUA is a program that an individual uses to send and receive email. Examples are Outlook in the Microsoft world and Ximian Evolution in the Linux world. An MUA can also be referred to as an email client. An email client fetches mail from a user's mailbox, but it sends mail via an MTA.
POP and IMAP servers require password authentication. The email password is the same as the user account password.
POP server access is much more common that IMAP, even though IMAP has more features. You may or may not want to run an IMAP server.
POP and IMAP are normally run under inetd.
There are two main protocols used for moving email, Simple Mail Transfer Protocol (SMTP) and Post Office Protocol (POP). SMTP is the protocol used to move email over the internet. POP is the protocol used to fetch mail from a user mailbox. A third protocol, Internet Message Access Protocol (IMAP) is similar to POP in that it's used to collect mail. It has a few more features, but it's not as widely used.
When you hit the send button on your email client (say, Outlook Express), the message is sent using SMTP to your domain's Mail Server (say, Postfix). That Mail Server looks at the domain part of the recipient's address and contacts the Mail Server for the recipient's domain. It then transfers the message using SMTP.
When someone sends you an email, they send it SMTP to their domain's Mail Server. Their Mail Server then connects to your domain's Mail Server and transfers the message. Your domain's Mail Server puts it into your mail box ready for your email client to pick up. At regular intervals, your email client will ask the POP server to check the mailbox. When it finds a new message, the POP server will transfer it to your email client.
There are some variations and alternatives to the above method, but the above is a good general description.
A Mail Server is a collection of servers and clients using SMTP and POP to handle mail for a domain or domains.
Here's my attempt to clear up some of the terminology involved with email. An MTA such as Postfix is actually both an SMTP server and an SMTP client. It's a client when it contacts another MTA and delivers mail to it. It's a server when it accepts a connection from an MUA or another MTA.
An MUA such as Outlook Express is both an SMTP client and POP client. It's an SMTP client when it contacts an MTA to send mail for it. It's a POP client when it asks a POP server to fetch mail from its mail box.
Now might be a good place to introduce a program called Fetchmail. Fetchmail is a POP client that fetches mail from a mailbox and delivers it using SMTP to an MTA. It's sometimes used when mail for a domain is forwarded to a single POP mailbox.
So a Mail Server is really a collection of clients and servers that service email for a domain. The main services that you need to run are an MTA and a POP and/or IMAP server.
SMTP was originally designed to make it easy to relay mail between Mail Servers. A Mail Server would accept mail not destined for one of its local users and relay on to the recipient's Mail Server. In fact, this is how mail is sent from the user's email client. The email client connects to it's own Mail Server rather than that of the recipient. This local server then relays the mail to its destination. However, such a free and open system is subject to abuse, and spammers quickly learned to hide themselves by relaying mail through another Mail Server. An open relay is an MTA that will accept mail from anywhere and forward it on to the recipient's Mail Server. It's imperative that your Mail Server is not an open relay. If it is, then spammers will find it and abuse it. They'll send spam via your server and the email header will indicate that it came from you. You will get blacklisted and many Mail Servers will no longer accept legitimate mail from you. And your upstream provider will very likely block your mail or disconnect you altogether. Your Mail Server needs to be configured to accept incoming only for local recipients, and outgoing mail only from trusted users. Trusted users are normally those on your local network This is the default mode of operation for most MTAs.