This article was first published slightly modified on my blog.
At Interhyp the email is one of our main tools of how we communicate with our customers. But even if you don’t work at Interhyp, the email is a tool we are using daily. It is safe to assume that if you are using a computer, you probably have used emails before. But do you know how emails work underneath? In this article I’ll explain to you how emails work in simple terms by using analogies to the real world.
Before we start, we have to first understand a few terms. There will be a lot of abbreviations and it may not make sense at first. But they are important as we refer to them when I explain the whole picture.
Servers and application
You need different kind of software applications, when sending and receiving mails.
On your local computer you have a Mail User Agent (MUA). This is a software application that is able to read and send mails. MUA can be divided between client based systems and web based systems. Client based systems can only be accessed via a private user agent applications installed on a computer. For web based systems you don’t need to install an application because they can be accessed via the internet. Examples for client based systems are Mozilla Thunderbird, Microsoft Outlook, etc. Examples for web based systems are Google GMail, Yahoo Mail, etc.
When sending, your MUA communicates with a specialized mail server, a Mail Transfer Agent (MTA). Unlike normal servers that communicate with each other via IP, the MTAs communicate with each other via SMTP. More on that later.
When receiving, your mails are delivered by a special kind of mail server, a Mail Delivery Agent (MDA). MDAs are responsible for receiving and storing your emails. MDAs are also known as „MX hosts“ or „mail exchanger“.
A Domain Name Server (DNS) is responsible for resolving IP addresses to domain names and vice versa. In the context of emails it is used to find the email server of the recipient.
Sending and receiving mails follow certain protocols. I’ll also explain to you some old protocols that are still being used by some email servers.
When sending and receiving emails, your MUA uses the Simple Mail Transfer Protocol (SMTP). SMTP was first published 1981 and is still being used today. SMTP is basically the language the MTAs are talking with each other when sending and receiving mails.
POP3 stands for Post Office Protocol Version 3 and is an application-layer protocol that provides access via an Internet Protocal (IP) network for a MUA to contact a mailbox on a MDA server. POP3 can download, delete, or retain your mails from the MDA server. POP3 has a major disadvantage though: It is unidirectional. Once it has downloaded your emails, your email client takes care of all the status flags, i.e. “sent”, “deleted”, “answered”, etc. POP3 was created in order to cope with temporarily internet disconnections and was commonly used back then when dial-up modem were used to connect to the internet.
As internet connections became more reliable and online storage space became cheap, POP3 was replaced by Internet Message Access Protocol (IMAP). IMAP allows bidirectional communication between the mail client and mail server, therefore multiple mail clients, e.g. on your tablet or your smartphone, can manage the same mailbox on a mail server. It is doing so by saving a copy of your mails on a mail server and your email clients on all of your devices synchs with the server, e.g. if you read your email on your tablet and later look it up on your smartphone, the email on your smartphone will be marked as “read”. Thus, your mails can be read from your desktop PC, laptop, smartphone, etc. in the same way. IMAP also has an offline mode, i.e. if you don’t have internet access you can still read and send emails. Once you have internet connection again your email client will synch with the server and will mark the email as “read” resp. sends it (and mark it as “sent”). POP3/IMAP are used for retrieving emails.
The following diagram shows the workflow of how the email is sent:
1. Let’s say your email address is “firstname.lastname@example.org” and you want to send it to “email@example.com”. You compose an mail on your computer. Once you hit “send”, the MUA will put the content into the body of the email and recipient, subject, date, etc. into the header. A snippet of the header of a mail looks like this
This is like you writing a letter and put it into an envelop and writing your address as the sender and the address of the recipient and then send it to the letterbox.
2. Based on the information in the mail header, your MUA contacts a MTA associated with your domain, i.e. “server-a.com” via SMTP. The MTA doesn’t understand where to send your mail to the address, “firstname.lastname@example.org”, because it can only understand IP addresses. It contacts the DNS in order to resolve the email email@example.com into an IP address.
This is like your letter has arrived at the postal office and is now looking up where to send your mail to.
3. The DNS translates firstname.lastname@example.org to an IP addresss like “12.345.67.89”. Imagine the DNS as a big table with two columns containing domain addresses and IP addresses respectively. The DNS then checks if the IP address has a Mail eXchanger (MX) record. The MX record is a resource record which specifies the mail server of a domain name.
This is like the postal office is looking up the recipient’s address and checks whether the provided recipient’s address has a mailbox, post-office box, or poste restante to send the letter to.
4. Once the DNS sends the IP address to the MTA, the MTA will transmit your message via different MTAs until it arrives at the recipient’s MTA. The MTA forwards your mail to a MDA. The MDA stores your mail until the recipients retrieves it.
This is like the postal office is calculating the best route. During the route your mail is delivered from one package station to the next until it reaches the package station in your city. Then the post man delivers it to the recipient’s address and put it into the recipient’s mail box, or post-office etc.
5. Once the mail was delivered. The recipient opens his MUA. Depending on whether the recipient uses client based mail or web based mail, the client downloads the emails from the MDA into your local computer resp. your email client synchs with the MDA and displays your emails with their latest statusses.
The last step is basically you open your mail box. 🙂
At the end it is not that complicated and is very similar to how the real mail is delivered. Do you have any questions? Comment below and let me know.