Friday, May 31, 2013

How Email Works? Email Basic Concepts

From an email client, you’ll typically compose a message, attach any necessary files, and send it to the recipient. But, have you wondered what happens behind the scenes? How the email is sent from your outbox to the recipients inbox? In this article, we will explain the basis of email. For those who already know this stuff, this might be a quick refresher.

What is an Email?

Till 1971, people were able to send messages to other people working on same system only. In 1971, the first e-mail message was sent by Ray Tomlinson. Though that was a very simple message based communication but it formed the basis of how advanced e-mails have become today.
The main components of an e-mail system that facilitate sending and receiving of e-mails on Internet are :
  • An e-mail client
  • An e-mail server (SMTP server)
  • POP and IMAP servers.
Lets study these and then finally try to connect the dots to understand the complete system.

An Email Client

If you use e-mails for online communication the you would definitely be using  an e-mail client. An e-mail client provides you with the following capabilities :
  • Provides a list of messages that people have sent to you. Each entry in the list contains the name of sender, a subject, a few words from the message body and the time/date on which it was received.
  • Provides the ability to read a complete message, reply to it or forward it to other people.
  • Provides the ability to compose a new message and send it to the desired recipients.
  • Delete a message.
The e-mail clients could be standalone (like Microsoft Outlook, Pegasus etc) or could be web based (like gmail, yahoo etc). There could be many advanced abilities that e-mail clients may provide but whatever the type of e-mail client be, the core abilities described above are provided by all type of clients.

An Email Server

Whenever you send a message from your e-mail client, it goes to an e-mail server. The e-mail server manages the messages received by it. It forwards the message to a POP or IMAP service if the message is to be sent to a recipient on the same subnet else it follows the standard procedure to send the message over Internet to the destined person.
An e-mail server comes into the picture twice if e-mail is sent over Internet to a remote destination. First it’s the sender’s e-mail server that sends the e-mail over the Internet and second is the receiver’s e-mail server that receives the e-mail and makes sure that it is delivered to the recipient’s system. On the other hand, an E-mail server comes into picture only once when the recipient is on the same subnet.

SMTP servers are widely used as e-mail servers all over the internet. An SMTP server is also known as Mail Transfer Agent (MTA).

You also may want to read Journey of a Data Packet in Internet, which explains how packets traverse on Internet.

POP and IMAP Servers

As already explained, these servers come into the picture when a message is received by SMTP server and it needs to be forwarded to the actual recipient. Let’s discuss both these servers one by one :

POP
POP stands for Post Office Protocol. A POP (or POP3) server in it’s simplest form stores the messages for a particular user in a text file. The file for a particular user is appended with information each time an e-mail is received by a POP server.  If your e-mail client is configured to use a POP3 protocol then whenever you try to fetch e-mails through your e-mail client then a request is sent to your POP server for the same.
A POP server requires the log-in credentials of a user that are sent through e-mail client. Once a user is authenticated, the POP server provides access to user’s e-mails.  As with any client server architecture, the e-mail client interacts with the POP server through a predefined set of commands.
Here is a list of common commands used to interact with POP server :
  • USER  – For User-ID
  • PASS   – For Password
  • LIST   – Provide message list
  • DELE – To delete a message
  • QUIT  – To end the interaction
Please note that the e-mail client connects to port 110 on the server where POP service is running. After connecting the e-mail client issues the commands (as described above) to the POP server to authenticate, fetch e-mail, list e-mails etc.
One small problem with POP servers is that once an e-mail client fetches the e-mails from this server on client machine, it gets difficult to access the same e-mails from any other device or system as they get downloaded on client machine and are removed from the server.  Though there exists and option ‘Keep a copy on server’ through which e-mail clients can tell the server not to delete the e-mails. But, this leads to multiple copies of your mailbox on clients as well as on server and so it makes the management of e-mails difficult.

IMAP
IMAP stands for Internet message access protocol. This protocol is also used to access e-mails but it is far more capable than POP. One of the most prominent feature an IMAP server provides is the central access to e-mails. Unlike POP server, an IMAP server keeps the e-mails on the server itself and so you can access e-mails from any machine or device.
This server also provides easy management of e-mails like searching, categorizing the e-mails and placing them into various sub-folders etc. The only problem that one could imagine with IMAP server is that you always need an Internet connection so that the e-mail client is able to fetch e-mails from the IMAP server. But today, almost all of the e-mail clients have the capability to cache the e-mails so that you can even view them when you are offline.
To interact with IMAP server, the e-mail client connects to server machine on port 143. As with POP, IMAP server also understands a set of commands which the e-mail client uses to connect with the server.

Connecting the Dots

With the understanding of all the major components used in e-mail system, lets connect the dots and understand how the whole e-mail system works:

  • An e-mail client like Gmail, yahoo, outlook etc is used to create or reply to an e-mail.
  • Once the e-mail is drafted successfully, it is sent using the e-mail client.
  • This e-mail first goes to the SMTP server (also known as MTA (Mail transfer agent) ) to which the e-mail client is connected.
  • The e-mail server looks out for the recipients address. The address is of the form <name>@domain.com
  • The e-mail server first uses the DNS technique to resolve the domain name into a valid IP address.
  • Next it sends the e-mail to to this IP address over the Internet.
  • Now the e-mail traverses over the Internet in a series of IP packets and reaches the destination SMTP server or the MTA.
  • This server collects all the e-mails and places them to appropriate location so that these are accessible to your e-mail clients through POP or IMAP services.
There you have it. That is how e-mail system works.


source :http://www.thegeekstuff.com/2013/05/how-email-works/