Introduction to Internet Mail
When you use a mail client program like Outlook or Evolution to send email, the program simply passed the message to a mail server for delivery to the destination. This server (also known as the MTA or Mail Transfer Agent) locates the correct system for the destination address, connects to the MTA on that system and transmits the message. When the other server receives the email, it checks to make sure it is truly destined for this system and if so stores it in a local mail file.
Later when the destination user checks his email, the file is read by a program such as Elm, Pine or Usermin, or by a POP3 server. Mail clients like Evolution and Outlook are usually run on a different system to the mail server, and use the POP3 protocol to download messages for local storage. Once the email has been retrieved in this way, the delivery process is complete and it can be read by a user.
Mail transfer agents use the SMTP (Simple Mail Transfer Protocol) to send email to each other over the Internet. Clients also use SMTP to send mail to servers for onward delivery. Very few MTAs implement the POP3 protocol for mail retrieval - instead, they simple write mail to a file which is read by a separate POP3 server program. Chapter 15 explains how to enable a POP3 server on your system, and chapter 33 explains the protocol in a little more detail.
The mail server that a client contacts to send a message is usually on its local network, at the ISP the client system is connected to, or even the same system. Ideally, this first MTA will directly contact the destination server, but this is not always the case. The destination MTA may be down or unreachable, in which case email will be sent to an alternate server instead. SMTP forwarding rules or per-user mail forwarding settings may cause email messages to be sent to other servers before it is finally delivered into a mailbox file.
If you want your system to be able to receive email, you will need to run a mail transfer agent program. This is only the first step though - to run your own mail domain such as example.com so that mail to firstname.lastname@example.org is delivered to the mailbox foo on your system, some network and DNS configuration is required. Typically, your system will need a fixed IP address and a permanent connection to the Internet. This means that running a proper mail server on a system connected occasionally via dial-up is impractical.
For other servers on the Internet to know to send mail to your system, appropriate DNS records must be created. Typically, an MX (Mail Server) record is defined for the domain, like example.com, that has the hostname of your system as its value, like server.example.com. This tells other MTAs to connect to your system to deliver email for the example.com domain. If you are running your own DNS server for the domain, chapter 30 explains in detail how to create an MX record. Otherwise, you will have to tell whoever is hosting the domain (for example your ISP) to add the correct record.
In fact, it is possible for any system to receive email addresses to its full Internet hostname, such as email@example.com. As long as there is no MX record matching linuxbox.example.com, other mail servers will do a normal A (address) record lookup for the hostname and connect directly to the system.
Sometimes, it does make sense to run a mail server even if you have a dynamically assigned IP address or ephemeral Internet connection. The Fetchmail Mail Retrieval program (covered in chapter 33) can be used to download email using the POP3 protocol and deliver it to a local mailbox on your system, which requires that an MTA be running. This local mail server may never accept a direct SMTP connection from another system on the Internet, but it can still deliver mail sent by programs on your system to local mailboxes.
Occasionally it is useful (and even necessary) to run a mail server that only deals with outgoing mail send by local client programs, and not with delivering incoming messages. Instead of configuring mail clients to use a remote MTA (such as the one at your ISP), you can tell them to use your own system's mail server instead. It will accept messages from local clients and try to deliver them to their final destinations, or put them in a queue for later delivery. Some programs that send email can only use a local mail server, which they connect to by running the sendmail program.
Because almost all ISPs and companies run their own mail servers, if you are happy to use an email address at your organization or ISPs domain there is no need to run your own. Instead, you can simply configure your Linux mail client like KMail or Evolution to download mail from and send out email via another server. For most people who just have a single email address and don't need to host their own email domain, there is no need to set up a mail server.