E-mail - What is it and how does it really work?
(Borrowed from howstuffworks)

Have you ever wondered how e-mail gets from your desktop to a friend halfway around the world? What is a POP3 server, and how does it hold your mail? The answers may surprise you, because it turns out that e-mail is an incredibly simple system at its core. In this article, we'll take a look at e-mail and how it works.

An E-mail Message
An e-mail message has always been nothing more than a simple text message -- a piece of text sent to a recipient. In the beginning and even today, e-mail messages tend to be short pieces of text, although the ability to add attachments now makes many e-mail messages quite long. Even with attachments, however, e-mail messages continue to be text messages.

The E-mail System
Given that you have an e-mail client on your machine (like Microsoft Outlook, Eudora, or Pegasus), you are ready to send and receive e-mail. All that you need is an e-mail server for the client to connect to.

We know that machines on the Internet can run software applications that act as servers . There are Web servers, FTP servers, telnet servers and e-mail servers running on millions of machines on the Internet right now. These applications run all the time on the server machine and they listen to specific ports , waiting for people or programs to attach to the port.

For the vast majority of people right now, the e-mail system consists of two different servers running on a server machine. One is called the SMTP server , where SMTP stands for Simple Mail Transfer Protocol. The SMTP server handles outgoing mail. The other is either a POP3 server or an IMAP server , both of which handle incoming mail. POP stands for Post Office Protocol, and IMAP stands for Internet Mail Access Protocol. A typical e-mail server looks like this:


The SMTP server listens on well-known port number 25, POP3 listens on port 110 and IMAP uses port 143.

The SMTP Server
Whenever you send a piece of e-mail, your e-mail client interacts with the SMTP server to handle the sending. The SMTP server on your host may have conversations with other SMTP servers to actually deliver the e-mail.



Let's assume that I want to send a piece of e-mail. My e-mail ID is brain , and I have my account on gilmoredesigngroup.com . I want to send e-mail to jsmith@mindspring.com . I am using a stand-alone e-mail client like Outlook Express.

When I set up my account at gilmoredesigngroup, I told Outlook Express the name of the mail server -- mail.gilmoredesigngroup.com . When I compose a message and press the Send button, here is what happens:
  1. Outlook Express connects to the SMTP server at mail.gilmoredesigngroup.com using port 25 .
  2. Outlook Express has a conversation with the SMTP server, telling the SMTP server the address of the sender and the address of the recipient, as well as the body of the message.
  3. The SMTP server takes the "to" address (jsmith@mindspring.com) and breaks it into two parts:
    • The recipient name (jsmith)
    • The domain name (mindspring.com)
If the "to" address had been another user at gilmoredesigngroup.com, the SMTP server would simply hand the message to the POP3 server for gilmoredesigngroup.com (using a little program called the delivery agent ). Since the recipient is at another domain, SMTP needs to communicate with that domain.
  1. The SMTP server has a conversation with a Domain Name Server , or DNS . It says, "Can you give me the IP address of the SMTP server for mindspring.com?" The DNS replies with the one or more IP addresses for the SMTP server(s) that Mindspring operates.
  2. The SMTP server at gilmoredesigngroup.com connects with the SMTP server at Mindspring using port 25. It has the same simple text conversation that my e-mail client had with the SMTP server for gilmoredesigngroup, and gives the message to the Mindspring server. The Mindspring server recognizes that the domain name for jsmith is at Mindspring, so it hands the message to Mindspring's POP3 server, which puts the message in jsmith's mailbox.
If, for some reason, the SMTP server at gilmoredesigngroup cannot connect with the SMTP server at Mindspring, then the message goes into a queue. The SMTP server on most machines uses a program called sendmail to do the actual sending, so this queue is called the sendmail queue . Sendmail will periodically try to resend the messages in its queue. For example, it might retry every 15 minutes. After four hours, it will usually send you a piece of mail that tells you there is some sort of problem. After five days, most sendmail configurations give up and return the mail to you undelivered.

The POP3 Server
In the simplest implementations of POP3, the server really does maintain a collection of text files -- one for each e-mail account. When a message arrives, the POP3 server simply appends it to the bottom of the recipient's file.

When you check your e-mail, your e-mail client connects to the POP3 server using port 110 . The POP3 server requires an account name and a password . Once you have logged in, the POP3 server opens your text file and allows you to access it. Like the SMTP server, the POP3 server understands a very simple set of text commands.

Your e-mail client connects to the POP3 server and issues a series of commands to bring copies of your e-mail messages to your local machine. Generally, it will then delete the messages from the server (unless you've told the e-mail client not to).

You can see that the POP3 server simply acts as an interface between the e-mail client and the text file containing your messages. And again, you can see that the POP3 server is extremely simple! You can connect to it through telnet at port 110 and issue the commands yourself if you would like to!

The IMAP Server
As you can see, the POP3 protocol is very simple. It allows you to have a collection of messages stored in a text file on the server. Your e-mail client (e.g. Outlook Express) can connect to your POP3 e-mail server and download the messages from the POP3 text file onto your PC. That is about all that you can do with POP3.

Many users want to do far more than that with their e-mail, and they want their e-mail to remain on the server. The main reason for keeping your e-mail on the server is to allow users to connect from a variety of machines. With POP3, once you download your e-mail it is stuck on the machine to which you downloaded it. If you want to read your e-mail both on your desktop machine and your laptop (depending on whether you are working in the office or on the road), POP3 makes life difficult.

IMAP (Internet Mail Access Protocol) is a more advanced protocol that solves these problems. With IMAP, your mail stays on the e-mail server. You can organize your mail into folders, and all the folders live on the server as well. When you search your e-mail, the search occurs on the server machine, rather than on your machine. This approach makes it extremely easy for you to access your e-mail from any machine, and regardless of which machine you use, you have access to all of your mail in all of your folders.

Your e-mail client connects to the IMAP server using port 143 . The e-mail client then issues a set of text commands that allow it to do things like list all the folders on the server, list all the message headers in a folder, get a specific e-mail message from the server, delete messages on the server or search through all of the e-mails on the server.

One problem that can arise with IMAP involves this simple question: "If all of my e-mail is stored on the server, then how can I read my mail if I am not connected to the Internet?" To solve this problem, most e-mail clients have some way to cache e-mail on the local machine. For example, the client will download all the messages and store their complete contents on the local machine (just like it would if it were talking to a POP3 server). The messages still exist on the IMAP server, but you now have copies on your machine. This allows you to read and reply to e-mail even if you have no connection to the Internet. The next time you establish a connection, you download all the new messages you received while disconnected and send all the mail that you wrote while disconnected.
Gilmore Design Group