How E-mail Works

Source: Internet
Author: User
Tags domain name server mail account
How E-mail Works


Every day the citizens of the Internet send each other billions of e-mail messages. if you are online a lot, you yourself may send a dozen or two e-mails each day without even thinking about it. obviusly, e-mail has become an extremely popular communication tool in a very short time!

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!

What is an E-mail Message?
Apparently, the first e-mail message was sent in 1971 by an engineer named Ray Tomlinson. prior to this, you cocould only send messages to users on a single machine. tomlinson's breakthrough was the ability to send messages to other machines on the Internet, using the @ sign to designate the processing machine.

An e-mail message has always been nothing more than a simple text message, a piece of text sent to a recipient. when you send an e-mail message to a friend, you are sending a piece of text. in the beginning and even today, e-mail messages tend to be short pieces of text, although the ability to add attachments now makes too e-mail messages quite long. even with attachments, however, e-mail messages continue to be text messages -- we'll see why when we get to attachments.

Understanding E-mail Clients
You have probably already ed several e-mail messages today. to look at them you use some sort of e-mail client. examples include stand-alone software, free Web e-mail service, and e-mail service that requires payments. no matter which type of client you are using, you know that an e-mail client generally does four things:

  • It shows you a list of all of the 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 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.

    Sophisticated e-mail clients may have all sorts of bells and whistles, but at the core, this is all that an e-mail client does.

    Understanding a Simple E-mail Server
    Given that you have an e-mail client on your machine, you are ready to send and receive e-mail. all that you need is an e-mail server for the client to connect. let's imagine what the simplest possible e-mail server wocould look like in order to get a basic understanding of the process. then we will look at the real thing.

    If you have read the how stuff works article entitled How web servers and the internet work, then you 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. the simplest possible e-mail server might look like this:

  • It wowould have a list of E-mail accounts, with one account for each person who can receive e-mail on the server. my account name might be mbrain, John Smith's might be jsmith, and so on.
  • It wowould have a text file for each account in the list. So the server wowould have a text file in its directory named mbrain. txt, another named jsmith. txt, and so on.
  • When someone wants to send me a message, the person composes a text message ("Marshall, can we have lunch Monday? John ") in an e-mail client, and indicates that the message shocould go to mbrain.
  • When the person presses the send button, the E-mail client wocould attach to the E-mail server and pass to the server the name of the recipient (mbrain ), the name of the sender (jsmith) and the body of the message.
  • The server wocould format those pieces of information and append them to the bottom of the MBRAIN. TXT file. The entry in the file might look like this:
      From: jsmith
      To: mbrain
      Marshall, can we have lunch Monday? John

    There are several other pieces of information that the server might save into the file, like the time and date of receept and a subject line, but overall you can see that this is an extremely simple process!

    As other people send mail to mbrain, the server wocould simply append those messages to the bottom of the file in the order that they arrive. the text file wocould accumulate a series of five or 10 messages, and eventually I wowould log in to read them. when I want to look at my e-mail, my e-mail client wocould connect to the server machine. in the simplest possible system it wocould:

  • Ask the server to send a copy of the MBRAIN. TXT file.
  • Ask the server to erase and reset the MBRAIN. TXT file.
  • Save the MBRAIN. TXT file on my local machine.
  • Parse the file into the separate messages (using the word "From:" as the separator ).
  • Show me all of the message headers in a list.

    When I double-click on a message header, it wocould find that message in the text file and show me its body.

    You have to admit that this is a very simple system. Surprisingly, the real e-mail system that you use every day is not much more complicated than this!

    Understanding the real E-Mail System
    For the vast majority of people right now, the real 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 a POP3 server, where pop stands for Post Office Protocol. the POP3 server handles incoming mail. the SMTP server listens on well-known port number 25, while POP3 listens on port 110. A typical e-mail server looks like this:


    Understanding SMTP
    Whenever 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.


    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 I want to send e-mail to I am using a stand-alone e-mail client like Outlook Express.

    When I set up my account at howstuffworks, I told Outlook Express the name of the mail server -- When I compose a message and press the Send button, here is what happens:

  • Outlook Express connects to the SMTP server at using port 25.
  • Outlook Express has a conversation with the SMTP server. the conversation is an extremely simple set of text commands and responses (see below ). outlook express tells the SMTP server the address of the sender and the address of the recipient, as well as the body of the message.
  • The SMTP server takes the "TO" address (for example, and breaks it into two parts: 1) the recipient name (jsmith) and 2) the domain name ( ). if the TO address had been another user at, the SMTP server wocould simply hand the message to the POP3 server for (using a little program called the delivery agent ). since the recipient is at another domain, SMTP needs to communicate with that domain.
  • The SMTP server has a conversation with a Domain Name Server and says, "Can you give me the IP address of the SMTP server for "The DNS replies with the one or more IP addresses for the SMTP server (s) that Mindspring operates.
  • The SMTP server at 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 How Stuff Works, 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 how stuff works 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 so that you know there is some sort of problem. after five days, most Sendmail deployments give up and return the mail to you undelivered.

    The actual conversation that an e-mail client has with an SMTP server is incredibly simple and human readable. it is specified in public documents called requests for comments (RFC) and a typical conversation might look something like this:

      Helo test 250 Hello [], pleased to meet you mail from: 250 2.1.0 sender OK rcpt to: 250 2.1.5 jsmith... recipient OK data 354 Enter mail, end ". "on a line by itself from: to: subject: testing John, I am testing .... 250 2.0.0 e1NMajH24604 Message accepted for delivery quit 221 2.0.0 closing connection closed by foreign host.

    What the e-mail client says is in red, and what the SMTP server replies with is in green. the e-mail client introduces itself, indicates the from and to addresses, delivers the body of the message and then quits. you can, in fact, telnet to a mail server machine at port 25 and have one of these dialogs yourself -- this is how people "spoof" e-mail.


    You can see that the SMTP server understands very simple text commands like HELO, MAIL, RCPT and DATA. The list of most common commands is:

  • HELO-introduce yourself
  • EHLO-introduce yourself and request extended mode
  • Mail from:-specify the sender
  • Rcpt to:-specify the recipient
  • Data-specify the body of the message. To:, from: And subject: shocould be the first three lines.
  • Rset-Reset
  • Quit-quit the session
  • Help-get help on commands
  • VRFY-verify an address
  • EXPN-expand an address
  • Verb-verbose

    Understanding 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. here are the most common commands:

  • User-enter your user ID
  • Pass-enter your password
  • Quit-quit the POP3 server
  • List-list the messages and their size
  • Retr-retrieve a message number, pass it a message number
  • Dele-delete a message, pass it a message number
  • Top-shows the top x lines of a message, pass it a message number and the number of lines

    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 ).

    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 wowould like.

    Understanding Attachments
    Your e-mail client allows you to add attachments to e-mail messages you send, and also lets you save attachments from messages that you receive. attachments might include word processing documents, spreadsheets, sound files, snapshots, pieces of software, etc. usually an attachment is not text (if it was, you wowould simply include it in the body of the message ). since e-mail messages can contain only text information and since attachments are not text, there is a problem that needs to be solved.

    In the early days of e-mail, you solved this problem by hand using a program called uuencode. the uuencode program assumes that the file contains binary information. it extracts three bytes from the binary file and converts them to four text characters (that is, it takes 6 bits at a time, adds 32 to the value of the 6 bits and creates a text character ). what uencode produces, therefore, is an encoded version of the original binary file that contains only text characters. in the early days of e-mail, you wocould run uuencode yourself and paste the uuencoded file into your e-mail message.

    Here is typical output from the uuencode program:

      Begin 644 reports
      M9W) E <"B <& P _ (B O = F % R + VQO9R] H = '1p9"] W96 (V-C1F-BYA8V-<W, N; &] GM ('P @ 8W5T ("UF (# (@ + 60 @ (C/B ('P @ 8W5T (" UF (# $ @ + 60 @ (B8B (# X @ <V5A <F-HM + 61A = & $ M) # $ *? B] C; W5N = "UP86 = E <R! /('-O <G0 @/B! S = & % T <RTD, 0IC <"@ M? B] W96) S: 71E + V-G: 2UB: 6XO <W5G9V5S = "UD871A + V1A = & $ @ <W5G9V5S =" TDM, 0IC <"! ^ + W = E8G-I = & 4O8V = I + 6) I; B] W: & 5R92UD871A + V1A = & $ @ = VAE <F 4MM) # $ * 8 W @? B] W96) S: 7 1E + V-G: 2UB: 6XO96UA: 6QE <BUD871A + V1A = & $ @ 96UAL: 6 PM) # $ *? B] G971L; V <@/B! L; V = S + 20Q

    The recipient wocould then save the uuencoded portion of the message to a file and run uudecode on it to translate it back to binary. the word "reports" in the first line tells uudecode what to name the output file.

    Modern e-mail clients are doing exactly the same thing, but they run uuencode and uudecode for you automatically. if you were to look at a raw e-mail file that contains attachments, you wocould find that the attachment is represented in the same uencoded text format shown above!

    The simplicity of E-mail
    From this description, you can see that today's e-mail system is one of the simplest things ever devised! There truly is nothing to it. There are parts of the system -- like the routing rules in Sendmail -- that get complicated, but overall the system is as simple as it can possibly be.

    The next time you send an e-mail, you will now have the comfort of knowing exactly what is going on behind the scenes!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.