We use emails almost every day, whether it's for work or communicating with someone.
Suppose you're using Gmail and want to send an email to your friend. You enter their email address, write your message, and click Send.
That's all we do from our side.
But have you ever wondered how Gmail knows where to send that email, especially if your friend uses Yahoo or another email provider?
Just like HTTP, email also uses networking protocols to communicate between servers.
Let's see how an email travels from our application to the receiver's inbox and understand the different protocols involved.
How Does an Email Actually Travel?
When we send an email, it doesn't go directly from our computer to the receiver's computer. It goes through email servers, which handle sending, receiving, and storing emails.
But who manages these email servers?
Some companies maintain their own mail servers, while others use email providers like Google, Microsoft, or Zoho.
For example, suppose a company owns the domain example.com. It can set up its own mail servers to handle emails for addresses like employee@example.com.
Or it can use Google Workspace. Employees can still use employee@example.com, but Google takes care of sending and receiving their emails.
So, having our own email domain doesn't mean we need to run our own mail servers.
Now, let's see how an email travels when we send it from Gmail to Yahoo Mail. We'll also look at what changes when both people use Gmail or when we use a third-party email application like Thunderbird.
Sending an Email from Gmail to Yahoo Mail
Suppose you're using Gmail and want to send an email to your friend who uses Yahoo Mail.
You open Gmail in your browser, write your message, enter your friend's email address, and click Send.
Let's see what happens next.
1. Your email reaches Gmail's servers
Since we're using Gmail in a browser, our email first reaches Google's servers through HTTPS, the same protocol we learned about in our previous article.
Google receives the email and checks where it needs to be sent.
2. Gmail finds Yahoo's mail server
Suppose your friend's email address is friend@yahoo.com.
Gmail looks at the domain yahoo.com and needs to find which server receives emails for that domain.
To find it, Gmail uses DNS and looks for a special record called an MX (Mail Exchange) record.
An MX record tells us which mail servers handle incoming emails for a particular domain.
Once Gmail finds the mail server's name, it can find its IP address and connect to it.
3. Gmail sends the email to Yahoo
Now Gmail needs to transfer the email to Yahoo's mail server.
For this, it uses SMTP (Simple Mail Transfer Protocol).
SMTP is the protocol mail servers commonly use to send emails to each other.
Gmail connects to Yahoo's mail server, sends the message, and receives a response telling it whether the email was accepted.
4. Yahoo receives and stores the email
Once Yahoo accepts the email, it processes the message and delivers it to your friend's mailbox.
Now, how does your friend read it?
If they open Yahoo Mail in their browser, the browser uses HTTPS to communicate with Yahoo's servers and display the email.
But if they're using a third-party email application like Thunderbird, it can use IMAP or POP3 to access emails from Yahoo's servers.
We'll understand how IMAP and POP3 work shortly.
What If Both of You Use Gmail?
Now suppose you and your friend both use Gmail.
When you click Send, your browser sends the email to Google's servers using HTTPS, just like in our previous example.
But this time, Google doesn't need to find another email provider's mail server.
Since your friend also uses Gmail, Google can handle the delivery within its own mail system and store the email in your friend's mailbox.
Google may use SMTP or other methods to communicate between its internal servers, but it doesn't need to establish an SMTP connection with another email provider.
What If We Use a Third-Party Email Application?
So far, we've seen how emails work when we use Gmail directly in our browser.
But Gmail isn't the only application we can use to access our emails.
Suppose you have a Gmail account, but instead of opening gmail.com, you want to send and read your emails using an application like Thunderbird.
You can connect your Gmail account to Thunderbird and use it to manage your emails.
Now, when you send an email from Thunderbird, it can use SMTP to send the message to Gmail's outgoing mail server. Gmail then takes care of delivering it to the receiver.
Similarly, when you want to read emails, Thunderbird can use IMAP or POP3 to access the messages stored on Gmail's servers.
So, the main difference is how the application communicates with Gmail:
- Gmail in your browser: Uses HTTPS to communicate with Google's web service.
- Thunderbird/Third Party Applications: Can use SMTP to send emails and IMAP or POP3 to receive them.
Let's understand how SMTP, IMAP, and POP3 work.
Why Do We Use Different Protocols to Send and Receive Emails?
You might be wondering why we need SMTP to send emails and IMAP or POP3 to receive them. Why can't we use the same protocol for both?
Let's take a simple example.
Suppose we have a long wooden stick and a rope.
We can use the wooden stick to push an object away from us, but we can't easily use it to pull the object back.
Similarly, we can use a rope to pull an object towards us, but we can't use it to push the object away.
Email protocols work in a similar way.
- SMTP works like pushing: When we send an email, SMTP transfers it from our email application to the outgoing mail server, or from one mail server to another.
- IMAP and POP3 work like pulling: When we want to read emails, these protocols allow our email application to access messages from the mail server.
Let's see how each of these protocols works.
POP3 vs IMAP
We've seen that POP3 and IMAP are used to access emails from a mail server. But they work differently.
Let's understand POP3 first.
1. POP3 (Post Office Protocol Version 3)
Suppose you have a Gmail account and use it on two devices:
- Laptop: Thunderbird, connected to Gmail using POP3.
- Phone: Gmail opened in your browser.
Now suppose your friend sends you an email.
The email reaches Gmail's server and appears in your inbox. When you open Thunderbird on your laptop, it downloads the email from Gmail.
But what happens to Gmail's copy after downloading?
If you open Gmail → Settings → See all settings → Forwarding and POP/IMAP, you'll find several options.
1. Enable POP for all mail
Suppose you already have 1,000 emails in Gmail.
If you enable this option, Thunderbird can download your existing emails as well as new emails that arrive later.
2. Enable POP for mail that arrives from now on
Suppose you already have 1,000 emails, but you only want Thunderbird to download new emails.
You can select this option. Gmail makes emails arriving from that point onward available for POP download, instead of including your older emails.
Gmail also lets you decide what happens to its copy when Thunderbird downloads an email.
3. Keep Gmail's copy in the Inbox
Suppose Thunderbird downloads an email and you read it on your laptop.
When you open Gmail on your phone, the email will still be in your inbox. It might even appear as unread because POP3 doesn't synchronize the read status.
4. Mark Gmail's copy as read
Now suppose Thunderbird downloads an email, but you haven't opened it yet.
If you've selected this option, Gmail marks its copy as read as soon as it's downloaded.
So, when you open Gmail on your phone, the email already appears as read, even though you haven't actually read it in Thunderbird.
5. Archive Gmail's copy
Suppose Thunderbird downloads an email.
Gmail removes its copy from the inbox but keeps it under All Mail.
When you open Gmail on your phone, you won't find that email in your inbox, but you can still find it under All Mail.
The downloaded copy remains available in Thunderbird.
6. Delete Gmail's copy
Suppose Thunderbird downloads an email.
Gmail moves its copy to Trash, while the downloaded email can still remain on your laptop.
When you open Gmail on your phone, the email will no longer appear in your inbox. You can find Gmail's copy in Trash until it's permanently deleted.
What Happens When We Use POP3 on Multiple Devices?
POP3 doesn't synchronize changes between devices.
For example, if you read an email on your laptop, it might still appear as unread on your desktop. Similarly, if you move an email to another folder or delete it on one device, those changes won't automatically appear on the other device.
2. IMAP (Internet Message Access Protocol)
Now suppose we connect Thunderbird to Gmail using IMAP instead of POP3.
This time, Thunderbird can keep our emails and changes synchronized with Gmail's server.
Let's see what happens.
1. Reading emails
Suppose you read an email in Thunderbird on your laptop.
When you open Gmail on your phone, the same email appears as read.
If you mark it as unread again, that change also appears on your phone.
2. Deleting emails
Suppose you delete an email in Thunderbird.
With IMAP, the deletion is communicated to Gmail's server. Depending on your settings, Gmail may move it to Trash, archive it, or delete it permanently.
When you open Gmail on your phone, you'll see the updated result.
3. Moving emails between folders
Suppose you move an email into a folder called Work in Thunderbird.
If that folder is synchronized through IMAP, Gmail updates the corresponding folder or label.
You can then find the email in the same location when you open Gmail on your phone.
4. Saving drafts
Suppose you start writing an email in Thunderbird but don't finish it.
If Thunderbird saves it to Gmail's Drafts folder, you can open Gmail on your phone and continue writing.
5. Using multiple devices
Suppose you use Gmail on your laptop, desktop, and phone.
With IMAP, all three devices can access the same mailbox. When you read, move, or delete an email on one device, those changes can appear on the others.
Which One Should We Use?
If we mainly want to download emails and keep them on one device, POP3 can be useful.
But if we use the same email account on multiple devices and want everything to stay updated, IMAP is generally the better choice.
The main difference is that POP3 downloads emails, while IMAP allows us to access emails and keep changes synchronized with the server.
Finding a Domain's Email Servers
We can also check which mail servers handle emails for a particular domain using a simple command.
If you're using Linux, open your terminal and run:
dig MX gmail.com
You can replace gmail.com with any domain, such as amazon.com or your company's domain, to see which mail servers are responsible for receiving its emails.
Top comments (0)