Article 2005-1

How Internet email works

Introduction

You must know how to send an email to someone who has an email account, and retrieve emails from your email account, since the popularity of email is so great that it has became part of our daily life. However, you may not know every technical detail about how Internet email works. The following lists a number of important questions:

  • What is the sequence of events that takes place when you send an email to someone across the Internet?
  • What about the format of Internet email messages? This question includes how a message is defined, who defined it, and why it is defined in that way.
  • How is email content encoded and decoded?
  • You may have heard of some protocol names such as SMTP, POP3 and MIME, which are related to Internet email. What are their roles in the process of sending and retrieving an email?
  • You may also have heard of the terms ‘Mail User Agent (MUA)’ and ‘Mail Transfer Agent (MTA)’. So, what are they?

The service of Internet email has many similarities to the traditional postal mail. For example, we also need something like a postman to deliver an email to its destination, and something like a mailbox to store the emails of an individual. The diagram below depicts the sequence of events that takes place when a person sends an email to another person. The diagram also illustrates some important programs, protocols, and their position in the whole email system. The following describes the details of these events.

  1. Andy composes a message to Betty using his mail user agent (MUA). He inputs the email address of his correspondent and the message body, and then presses the send button.
  2. The MUA formats the message and uses the Simple Mail Transfer Protocol (SMTP) to send the message to the local mail transfer agent (MTA).
  3. The MTA looks at the destination address and looks up the destination domain name in the DNS to locate the mail exchange server (MX) that is able to accept email for that domain.
  4. The name server for the domain responds with the mail exchange server for that domain.
  5. The MTA sends the message to the MX using SMTP. The MX then stores the message in the mailbox of the user Betty.
  6. Betty presses the “get mail” button in her MUA. The MUA then retrieves the message using the Post Office Protocol (POP3).

How Email Works

To address all the questions I raise at the beginning. We need to learn about the following main topics about email systems.

  • Sending and receiving email: this part describes the basic format of an email, and the local part and domain name of an email address.
  • Mail User Agent (MUA): this part describes the role of a user agent, the basic services it provides to the users, and the types of user agent.
  • Multipurpose Internet Mail Extensions (MIME): this part is about the format of an Internet email message and how it is defined.
  • Simple Mail Transfer Protocol (SMTP) is the basic standard for email transmission across the Internet. However, the protocol has some limitations on message type and length. MIME is an extension of SMTP that standardizes additional fields for mail message headers that describe new types of content and organization for a message.
  • Mail Transfer Agent (MTA): an MTA is a computer process that transfers email messages from one host computer on the Internet to another. Its role is similar to what a postman does in the traditional postal mail system. Note that an MTA is also called a mail server or a mail exchange server.
  • Mail delivery: this part addresses the three stages in the delivery of an email from the sender to the receiver. It is related to what is illustrated in figure above.
  • Mail Access Protocols: this part covers two mail access protocols that enable a user to fetch email from the mailbox in the mail server to the user’s computer. The two mail access protocols are Post Office Protocol, version 3 (POP3) and Internet Mail Access Protocol, version 4 (IMAP4).

One good way to visualize how Internet email works is to do some real interactions with an SMTP server and a POP3 server. The following two activities will guide you to do these two experiments.

Activity 1

This activity is about how to use a DOS command prompt to connect to an SMTP server and communicate with it about sending an email message. Please follow the steps below carefully.

  1. You need to find the hostname of an SMTP server that you can access from your computer. You can find the information from your Mail User Agent (mail client) such as Microsoft Outlook Express. In the following description, ‘smtp.ouhk.edu.hk’ will be used as an example.
  2. Let’s now look at the basics of the SMTP. There are three steps to SMTP mail transactions. The first step is the sending of the “MAIL FROM” and “RCPT TO” messages by the sender, which give the sender’s identification and the receiver’s information. The second step is sending the “DATA” message, which gives the mail data. The last step is confirming the transaction by sending the end of mail data indicator.
  3. Open a DOS command prompt and type:

    telnet smtp.ouhk.edu.hk 25

    You should receive a response message from the server. For example, I received the following:

    220 ouhk.edu.hk ESMTP Sendmail 8.11.1/8.11.1; Fri, 30 Sep 2005 17:43:23 +0800 (HKT)

  4. Type “MAIL FROM:” followed by your email address. For example, I entered the following:

    MAIL FROM: andy@ouhk.edu.hk

  5. You should receive a response message from the server. I received the following message:

    250 2.1.0 andy@ouhk.edu.hk... Sender ok

  6. Type ‘RCPT TO:’ followed by an email address that you can access for later verification purposes. For example, I entered the following:

    RCPT TO: betty@stevenchoy.com

  7. You should receive a response message from the server. I received the following message:

    250 2.1.5 betty@stevenchoy.com... Recipient ok

  8. Type ‘DATA’ as shown in the following.

    DATA

  9. You should then receive a response message from the server similar to the following:

    354 Enter mail, end with "." on a line by itself

  10. Type the message you want to send for testing. Press return when you finish a line. Finally, type ‘.’ to tell the server that is the end of the message. The following is what I entered in my testing:

    This is the first line of testing message.
    This is the second line of testing message.
    .

    (Note that the third line is not blank. Remember to type ‘.’ as the last line in your testing. A new line containing only ‘.’ means the end of the message body.)
  11. The server should respond with some appropriate message.

    250 2.0.0 j8U9hrH01679 Message accepted for delivery

  12. Finally, use your mail client program to log in to the receipt email account and fetch the testing email. This step is to verify that what you have done from steps 1 to 10 has been successful.

Note: A detailed description of the SMTP protocol can be found in the document ‘Request for comments document on SMTP, RFC 2821’, which can be found at: http://www.ietf.org/rfc/rfc2821.txt. Note that RFC 2821 replaced the obsolete RFC 821 as of 2001.

Activity 2

This activity is about how to use a DOS command prompt to connect to a POP3 server and communicate with it about fetching an email message. Please follow the steps below carefully.

  1. You need to find the hostname of a POP3 server that you can access from your computer. You can find the information from your Mail User Agent (mail client) such as Microsoft Outlook Express. In the following description, ‘mail.stevenchoy.com’ will be used as an example.
  2. Open a DOS command prompt and type: telnet mail.stevenchoy.com 110
  3. The following shows you a sample dialogue between the client and the server. You can follow similar steps to communicate with the POP server to fetch some emails to read — or even delete some. The dialogue between the client and the server are shown in bold and type setting. What you need to type is shown in each client’s input.
    Server: +OK Hello there. (Connected successfully)
    Client: USER betty (Tell the username of the email account)
    Server: +OK User accepted
    Client: PASS xxxxxxxx (Tell the password of the account)
    Server: +OK Pass accepted
    Client: STAT (Ask how many messages are in the mailbox)
    Server: +OK 2 380 (Respond with the total number and the total size of messages)
    Client: LIST (Ask to list one by one all the message numbers and their size)
    Server: +OK 2 messages (380 octets)
    1 180
    2 200

    Client: RETR 1 (Ask to list the content of the message number 1)
    Server: +OK 180 octets (The server also sends the contents of message 1.)
    Client: DELE 1 (Ask to delete message 1)
    Server: +OK message 1 deleted
    Client: QUIT (End the communication and quit)
    Server: +OK Bye-bye

Note: A detailed description of the POP3 protocol can be found in the document ‘Request for comments document on Post Office Protocol — Version 3, RFC 1939’, which can be found at: http://www.ietf.org/rfc/rfc1939.txt.

Summary

SMTP and POP3 are two well-known protocols that support email on the Internet. SMTP is used to transmit email across the Internet, while POP3 is used to receive email from a mail server. The above two activities have allowed you to experience that both SMTP and POP3 are relatively simple, text-based protocols. It is quite easy to test an SMTP server and a POP3 server using the telnet program. What a MUA (Mail User Agent) does in addition to handling SMTP and POP3 includes using MIME to encode and decode multimedia and other non-ASCII messages, and provides you with a good user interface.

About the article

This article is derived from a small section in a written teaching publication I did for a distance-learning course on computer networks. The work is:

Choy, S O (2005) ‘The end users’ Internet applications’, unit 8 in CT332 Computer Networks, Hong Kong: The Open University of Hong Kong.

Comments are welcomed. Go to this place to leave your comments if you have anything to say about this article.