|
Introduction:
This document describes how electronic mail (e-mail) works. It begins by defining some terms and concepts which are very important part of e-mail (High-Level Concepts). Several terms and concepts are discussed briefly and some in great details. It also explains a deeper layer of e-mail (Low-Level Concept) briefly.
High-Level Concept:
Mail-Box:
A mail-box is a file or a directory of files, where incoming messages are stored. It is known as inbox.
Mail User Agent (MUA) or E-Mail Client (EMC):
A mail user agent (in UNIX world) or E-mail Client (in Windows world) is an application run directly by a user. The table below shows Examples of MUA or EMC in different OSs:
OSs |
MUA or EMC |
UNIX or LINUX |
elm, mailx, mh, zmail, exmh & Netscape |
WINDOWS |
Outlook Express, Eudora, Pegasus & Netscape |
MAC |
Eudora & Netscape |
No matter which type of MUA or EMC you are using, you know that a MUA or a EMC generally does four things:
- It shows you a list of all messages in your mailbox by displaying the message headers. The header shows you who sent the mail and the subject of the mail, and may also show the time and the date of the message and the message size.
- It lets you select a message header and read the body of the e-mail message.
- It lets you create new messages and send them. You type in the e-mail address of the recipient and the subject for the message, and then type the body of the message.
- Most e-mail clients also let you add attachments to messages you send and save the attachments from messages you receive.
Mail Transfer Agent (MTA):
Mail Transfer Agents (MTA) are used to transfer messages between machines. MUAs give the message to the MTA, who may pass it onto the another MTA or possibly many other MTAs. Users may give messages to the MTAs directly, but requires some expertise on the part of the user and is recommanded for experts.
MTAs are responsible for properly routing messages to their destination. While their function is hidden from the average user, theirs is by far the most complex part of getting messages from their source to their destination. The most commen agent is sendmail(1m).
Sendmail
Sendmail is a Mail Transfer Agent (MTA), which is the program that moves mail from one machine to another. Sendmail implements a general internetwork mail routing facility, featuring aliasing and forwarding, automatic routing to network gateways, and flexible configuration.
Mail Delivery Agent (MDA):
Mail Delivery Agents are used to place a message into a user's mail-box. When the message arrives at its destination, the final MTA will give the message to the appropriate MDA, who will add the message to the user's mail-box. The standard MDA for Solaris 2.5 and above is, mail.local(1m).
A Simple E-Mail Server:
Given that you have an E-Mail Client (EMC) or a Mail User Agent (MUA) on your machine, you are ready to send and receive E-Mails. All that you need is an E-Mail Server for the client to connect to. Let's imagine what the simplest possible E-Mail Server would look like in order to get a basic understanding of the process. Then we will look at the real thing.
The simplest possible E-Mail Server might look like this:
- It would have a list of e-mail accounts, with one account for each person who can receive e-mail on the server. My account name in Computer Science (CS) domain is amin, Stan Swiercz's might be stan and so on.
- It would have a text file for each account in the list. So the sever would have a text file or mail drop in its directory named /var/mail/amin, another named /var/mail/stan and so on. Please see Figure1.
- When someone wants to send me a message, the person composes a text message ("Amin, Can we have a lunch Friday? Stan") in an E-Mail Client, and indicates that the message should go to amin.
- When the person presses the Send button, the E-mail Client would attach to the E-Mail Server and pass to the server the name of the recipient (amin), the name of the sender (stan) and the body of the message.
- The server would format those pieces of inforamtion and append them to the bottom of the /var/mail/amin file. The entry in the file might look like this:
From:stan
To:amin
Amin,
Can we have a lunch Friday?
Stan
There are several other pieces of the information that the server might save into the file, like the time and date of receipt and a subject line.
As other poeple send mail to amin, the server would simply append those messages to the bottom of the file in the order that they arrive. The mail drop would accumulate a series of five or ten messages, and eventually I would log in to read them. When I want to look at my e-mail, my E-Mail Client would connect to the server machine.
In the simplest possible system it would:
When I double click on a message header, it would find that message in the text file and show me the its body.
- For the vast majority of people right now, the real e-mail system consists of two different services (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 SMTP Server listens on well-known port number 25.
The other one is a POP3 Server, where POP stands for Post Office Protocol. The POP3 Server handles incoming mail.
The POP3 Server listens on well-known port number 110.
Figure 1: A typical E-Mail Server with an E-Mail Client looks like this:
What is a SMTP Server?
SMTP is a server service that runs on a server computer, and listens for incoming requests from Mail User Agent (MUA) or E-Mail Clent (EMC) to route mail. When you send a piece of e-mail, your E-Mail Client interacts with the SMTP server to do the sending. The SMTP Server on your host may have conversations with other SMTP servers to actually deliver the e-mail.
What is a POP3 Server?
In the simplest implementation of POP3, the server really does maintain a collection of text files or mail drops -- one for each e-mail account.
When a message arrives, the POP3 Server simply appends it to the bottom of the recipient's file.
What is an IMAP Server?
IMAP stands fot Internet Message Access Protcol. It is a method of accessing electronic mail or bulletin board messages that are kept on a (possibly shared) mail server. In other words, it permits a MUA or EMC program to access remote messages stores as if they were local.
For example, email stored on an IMAP server can be manipulted from a desktop computer at home, a workstation at the office, and a notebook computer while traveling, without the need to transfer messages or files back and forth between computers.
What is a port number?
A port number is a way to identify a specific process to which an Internet or other network message is to be forwarded when it arrives at a server. For the Transmission Control Protocol and the User Datagram Protocol, a port number is a 16-bit integer that is put in the header appended to a message unit. This port number is passed logically between client and server transport layers and physically between the transport layer and the Internet Protocol layer and forwarded on.
An Example: (Putting it all together)
Let's assume that I want to send a piece of e-mail. My e-mail ID is amin and I have my account on amin@cs.concordia.ca. I want to send email to stan@yahoo.com. I am using exmh E-Mail Client. (exmh is GUI [Graphic User Interface] of mh E-Mail Client)
When I set up my account at cs.concordia.ca, I told exmh the name of the mail server -- mailhost.cs.concordia.ca. Therefore for configuration purposes if you like to set up your SMTP Server to send e-mail, simply open a Netscape Communicator, click on Edit and invoke Preferences. A Preferences menu pops up, in the Category section, click on Mail & Newsgroups, and then click on the Mail servers. Type in your Outgoing mail (SMTP) server : your ISP's smtp.server.com.
In my case my Outgoing mail (SMTP) server is : mailhost.cs.concordia.ca as shown below:
When I compose a message and press the Send button, here is what happens:
EXCEPTIONS:
If for some reason the SMTP Server at cs.concordia.ca cannot connect with the SMTP Server at yahoo, then the message goes into the queue. The SMTP Server on most machines uses a Mail Transfer Agent (MTA). A most commen MTA which is sendmail, does the actual sending, so this queue is called sendmail queue. The sendmail will periodically try to resend the message in its queue. For example, it might retry every 15 minutes. After 4 hours it will usually send you a piece of mail so that you know there is some sort of problem. After 5 days, most sendmail configurations give up and return the mail to you undelivered. The above values are configurable to suit your needs, however the default values are 15 minutes, 4 hours and 5 days.
The actual conversation that an E-Mail Client has with an SMTP Server is very simple and human readable. It is specified in public documents called Requests For Comments (RFC).
A typical conversation might look something like this: Click here
How Stan gets his email?
As I mentioned above, in the simplest implementation 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 Stan checks his mail, his E-Mail Client connects to the POP3 Server using port 110. The POP3 Server requires an account name and a password. Once he has logged in, the POP3 Server opens his mail drop (/var/mail/stan) and allows him to access it. Like the SMTP Server, the POP3 Server understands a very simple set of text commands.
A typical text command might look something like this: Click here
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 machines. Generally it will then delete the messages from the server (unless you've told the E-Mail Client not to).
When I set up my account at cs.concordia.ca, I told exmh the name of the POP3 server -- mailhost.cs.concordia.ca. Therefore for configuration purposes if you like to set up your POP3 Server to read e-mail, simply open a Netscape Communicator, click on Edit and invoke Preferences. A Preferences menu pops up, in the Category section, click on Mail & Newsgroups, and then click on the Mail servers. In the Mail servers window click on the Edit button and type in your incoming (POP3) server : your ISP's POP3.server.com.
In my case my Incoming mail (POP3) server is : mailhost.cs.concordia.ca as shown below:
I have decided to tell to my exmh (MUA) to leave messages on the server as shown below:
Low-Level Concept:
Headers & Bodies
Each message consists of two parts. The headers contains information about who authored the message, the intended recipients, the time of creation, the subject of the message, delivery stamps, ... Each header is of form "keyword: value", where keyword is a special word (like From or Date) identifying the type of information contained in that header, and value is the information itself.
More information about message headers can be found in RFC 822 and RFC 1123.
A blank line always separates the headers from body.
The body contains the information the sender is trying to communicate. The "message" as most people think of it is really the body of the message.
MIME:
For many years, most messages were plain text in the US-ASCII character set, so no structure was needed for bodies. The recent explosion of messaging in Europe and Asia and the transmission of multimedia messages have brought about such a need.
MIME (Multipurpose Internet Mail Extensions), specified in RFCs 2045, 2046, 2047, 2048, and 2049, especially RFC 2045 and 2046, defines such a body structure. It specifies how a Content-Type header can be used to specify a particular character set or other non-textual data type for a message. For example, the header:
Content-Type: text/plain; charset=us-ascii
indicates that the message consists of plain text in the US-ASCII character set. MIME also specifies how to encode data when necessary. It is the responsiblilty of the receiving Mail User Agent (MUA) to use this information to display the message in a form that will be understood by the user.
Transfer Protocols:
The language spoken Mail Transfer Agents (MTAs) is known as a transfer protocol. There are many in existence; the most commen is SMTP; also well-known are UUCP (Unix-to-Unix copy) and X.400.
Envelops and Bodies
SMTP uses the concepts of an envelope to transfer messages; this merely contains about from whom the message originated and to whom it is destined. The originator address is important: in case there is a problem transferring or delivering the message, the originator can be notified.
The SMTP body is the entire message as defined above in Headers & Bodies. So the message headers plus the message body equals the SMTP body. The term SMTP body is not used that commonly, but it is important to distinguish it from the message body.
Routing
RFC 974 describes Mail Routing and the Domain Name System.
Mail eXchanger (MX) records are maintained by Domain Name Servers (DNS)to tell MTAs where to send mail messages. An MX record can be specified for a specific host, or a wild-card MX record can specify the default for a specific domain. The MX record tells an MTA where a message, whose ultimate target is a given host in a given domain, should be sent to next, i.e., which intermadiate hosts should be used to ultimately deliver a message to the target host.
sendmail specifics
MX records are maintained by DNS only (i.e. not host files or NIS). If no MX records are available for a given host, sendmail will try to send to that host directly. Once sendmail determines which host to attampt to send the message to: an intermediate host as indicated by an MX record, or a direct connection to the target host, it uses gethostbyname() to determine the IP-address of the target machine in order to make a connection.
The gethostbyname() library may use DNS, an /etc/hosts/ file, or NIS to perform its name-to-IP-address look-up, as configured by the /etc/nsswitch.conf file. N.B.: the host name passed to gethostbyname() may have been derived from an MX record if a domain name server is running, even though gethostbyname() may not use DNS to resolve this name's address. Remember that MX records are only available from DNS, and the name service switch does not affect a search for MX records. This is as required by RFC 1123, section 5.3.5 This situation may be most nocticeable when DNS is not first in the /etc/nsswitch.conf file. It may then be possible that a host name only in /etc/hosts/ or NIS be redirected by a wild-card MX record to another host.
|