DEV Community

Inam Ul Haq
Inam Ul Haq

Posted on

How Emails Reach an Inbox

What happens when you send a message on let's say Twitter? Leaving Twitter's business logic, the answer is simple. The message gets stored in a database with the ids of the sender and the receiver. Whenever needed, messages can be retrieved and displayed. It's easy, right? Well, emails are not!

Let's now see how emails reach an inbox/mailbox.

Bob sends an email to Sarah

Let's say Bob uses Gmail and Sarah uses Yahoo. Bob writes an email for Sarah and hits the send button.

Before going further, let me introduce two types of servers involved in this whole Email business; SMTP (Simple Mail Transfer Protocol) server and IMAP (Internet Message Access Protocol) server.

POP, an alternative to IMAP, can also be used, but we will discuss that another day.


SMTP servers send and receive emails. For the most part, SMTP servers do what's called relaying. After receiving and processing the email, the server tries to move (relay) the email to its destination. A destination can be another SMTP server or if the server itself is the destination, a directory/folder on the same server.

An email may pass through several SMTP servers before reaching its destination.


IMAP is simple. It just retrieves the emails from where SMTP left them and makes them available to be used by Email Clients. You might remember configuring your Email Client like Thunderbird to use your mailbox provider's provided IMAP settings. Some Email Clients do it automatically though.

When Bob and Sarah signed up for their respective mailbox providers (Gmail and Yahoo), both got accounts on their providers' SMTP and IMAP servers.

Now coming back to Bob and Sarah

After all the routing and DNS business, Bob's email reaches his SMTP server (Gmail). SMTP server processes the email and finds out its destination which is Yahoo's SMTP server. It then relays the email to Yahoo's SMTP server.

Yahoo's SMTP server receives the email and determines that it itself is the destination server. The server then just move the email to Sarah's mailbox (directory/folder) which is on the same server.

Sarah's mailbox has a new Email. Sarah's IMAP server makes the email available to be fetched by Email Clients. And Email Clients, checking up with the IMAP server after a specified interval, find out Sarah has a new email. Sarah gets a notification and now she can read it 🙌

Ask any question in the comments and I'll try to answer it!

Follow me on twitter @MeInamUlHaq

Also, checkout Free Email Verifier which I built.

Top comments (0)