How Email Works Pt. 1 ✉️

Amitosh Swain Mahapatra
4 min readApr 5, 2024

--

You received this mail and are now reading this on an email client, but have you ever wondered how did this mail reach you?

Email is an essential part of how we communicate in the 21st century. It’s also one of the most misunderstood technologies on the Internet. I’ll explore how email sending works behind the scenes in this post.

🪄 Trivia: History of email

Email is the most common form of electronic communication, with over 2.5 billion users worldwide. It was invented in 1971 by Ray Tomlinson, who sent the first email from one computer to another.

It took place on ARPANET — the precursor to what we now know as the Internet, using a protocol that later developed into FTP, a file-transfer protocol that was popular before HTTP took over. The early days of Email were much more rudimentary than what we use now.

🔎 Anatomy of an email address

An email address is a string of characters that looks something like this: joe@example.com

The domain name is the part after the @ symbol, which would be “example.com.” The domain can be one word or multiple words, which functions like an address for your email. Anyone sending you an email will send it to the email servers associated with your domain. You can sign up at one of the many public email services like Gmail or your ISP’s service, which provide you with a mail server, or you can build and run your own.

🚀 Sending email

Sending email is a two-step process. First, you find the mail server of your recipient. Then, you use the SMTP protocol to connect with the mail server and send your message. Sounds simple? Yes, it is!

🔎 Finding the mail server

You can find out which mail server to send your email to by looking up its domain name in DNS MX records: pick one randomly if it has multiple addresses listed.

Technically speaking, there is a priority that servers should follow — the number before the email hostname, but we can ignore it for our example.

If you have a Mac or a Linux system, you can run this command to see the MX records for a given domain. Here is an example for Gmail. You can see 5 SMTP servers listed in the DNS response.

$ dig -t MX gmail.com

; <<>> DiG 9.10.6 <<>> -t MX gmail.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25845
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;gmail.com. IN MX

;; ANSWER SECTION:
gmail.com. 2531 IN MX 20 alt2.gmail-smtp-in.l.google.com.
gmail.com. 2531 IN MX 10 alt1.gmail-smtp-in.l.google.com.
gmail.com. 2531 IN MX 40 alt4.gmail-smtp-in.l.google.com.
gmail.com. 2531 IN MX 5 gmail-smtp-in.l.google.com.
gmail.com. 2531 IN MX 30 alt3.gmail-smtp-in.l.google.com.

;; Query time: 53 msec
;; SERVER: 1.1.1.1#53(1.1.1.1)
;; WHEN: Mon Nov 20 12:20:51 IST 2023
;; MSG SIZE rcvd: 161

✉️ Sending Email

Once connected, you can send emails using the SMTP protocol. The SMTP protocol is a simple text-based protocol running on TCP, which is how mail servers and clients talk to each other to send and receive email.

Since it’s text-based, you can simulate an SMTP exchange using the telnet command. If you have telnet installed on a terminal, you can email yourself.

⚠️ Your success may vary based on whether your ISP allows you to send emails directly and your mail server enables you to send emails without a relay.

$ telnet gmail-smtp-in.l.google.com 25

Trying 2404:6800:4003:c1a::1b...
Connected to gmail-smtp-in.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP d12-20020a170902654c00b001c746b986e2si852655pln.346 - gsmtp
> HELO localhost
250 mx.google.com at your service
> MAIL FROM: <root@localhost>
250 2.1.0 OK d12-20020a170902654c00b001c746b986e2si852655pln.346 - gsmtp
> RCPT TO: <your.email@gmail.com>
250 2.1.5 OK d12-20020a170902654c00b001c746b986e2si852655pln.346 - gsmtp
> DATA
354 Go ahead d12-20020a170902654c00b001c746b986e2si852655pln.346 - gsmtp
> Test message from telnet
> .
250 Message accepted for delivery
> QUIT
221 mx.google.com closing connection

🔥 Modern-day email

Most people use email through a web client, which abstracts away all the complexities of sending and receiving email by performing all necessary transactions behind the scenes. Email servers, however, offer IMAP, POP3 and SMTP access if you want to use other email software (including mobile apps like Gmail Outlook) to send and receive emails.

You can still send and receive emails from a laptop by running an SMTP server on your local machine and setting the required MX records.

It’s hard to believe that email is more than 40 years old. The first message was sent in 1971; ever since then, it has become essential to our everyday lives. It’s easy to forget how many things we do with our inboxes — from keeping track of bills and receipts to communicating with friends worldwide. But even though we take this technology for granted now, its origins were quite humble: They started with two people who just wanted an easier way to send messages back and forth between each other!

In the next part, we will discuss what happens when you receive the email, including verification, spam filtering and archiving until you access it on your computer.

Originally published at https://recursivefunction.blog.

--

--