~/blog/mailServer
back
~/blog/mailServer
10 min read

Mail Server Explained: How Email Actually Works Behind the Scenes

March 16, 2026•10 min read•Guide
#Mail Server#Networking#SMTP#IMAP#POP3#Email Security#DNS

Mail Server Explained: How Email Actually Works Behind the Scenes

You type an email, hit send, and seconds later it appears in someone's inbox halfway across the world. Simple, right?

Not quite. Behind that effortless experience is a chain of systems working in precise coordination. Mail servers, transfer agents, delivery agents, DNS lookups, protocol handshakes. Most people never think about any of it, and that is exactly how it should be. But if you are learning to build or manage networked systems, understanding how email actually works is foundational.

This article breaks it all down: what a mail server is, how email travels from sender to recipient, the protocols involved, the different types of mail servers, and the security threats you need to know about.


What is a Mail Server?

A mail server is a dedicated system responsible for sending, receiving, managing, and storing email within a network.

Think of it as the digital equivalent of a post office. When you send a letter, you do not personally drive it to the recipient's house. You drop it at a post office, which routes it through a delivery network, and eventually it lands in the right mailbox. Mail servers work the same way.

Without a mail server, email as we know it simply does not exist.
Every address, every inbox, every sent folder is backed by one.

Key characteristics of a mail server:

  • Operates continuously in the background
  • Handles sending and receiving independently of your email application
  • Works the same regardless of which client (Gmail, Outlook, Thunderbird) sends the message
  • Manages storage, delivery rules, spam filtering, and access control

Why Not Just Use Personal Gmail?

A common question, especially in institutional settings, is why organizations bother with their own mail server instead of using personal accounts.

The answer comes down to identity, control, and compliance. A school email like guru@smkn1.sch.id carries official weight. It represents the institution, not an individual. Beyond branding, organizations need audit trails, data ownership, and the ability to manage accounts centrally. A personal Gmail account gives you none of that.


The Three Components of Every Email System

Before diving into how email travels, you need to understand the three distinct roles that make the whole system work. These components are the MUA, MTA, and MDA.

Mail User Agent (MUA)

The MUA is the application you interact with directly. It is your window into the email system.

What it does:

  • Lets you compose and read emails
  • Sends outgoing messages to the mail server
  • Retrieves incoming messages from the server using POP3 or IMAP
  • Handles your inbox, folders, and attachments

Examples: Gmail, Microsoft Outlook, Mozilla Thunderbird, Apple Mail, Yahoo Mail

The MUA never delivers email directly to the recipient. It hands the message off to the next component.

Mail Transfer Agent (MTA)

The MTA is the engine of the email system. It picks up the message from the MUA and moves it toward its destination.

What it does:

  • Accepts outgoing email from the MUA via SMTP
  • Queries DNS to find the recipient's mail server
  • Forwards the message to the correct server
  • Manages queuing if the destination server is temporarily unreachable

Examples of MTA software: Postfix, Sendmail, Microsoft Exchange Server

If your message needs to cross from one domain to another (say, from @gmail.com to @outlook.com), the MTA on the sender's side negotiates directly with the MTA on the receiver's side.

Mail Delivery Agent (MDA)

Once the message reaches the destination server, the MDA takes over.

What it does:

  • Receives the message from the MTA
  • Applies delivery rules (spam filters, folder sorting)
  • Saves the message to the correct user's mailbox
  • Makes the message available for retrieval via POP3 or IMAP

The MDA is the last stop before the recipient opens their inbox.


How Email Actually Travels: Step by Step

Here is the complete flow of an email from the moment you click send to the moment it appears in someone's inbox.

Sender (MUA) → MTA Pengirim → DNS / MX Record → MTA Penerima → MDA → Penerima (MUA)

Let's walk through each step.

Step 1 — The sender writes and sends the email (MUA)

You compose a message in your email client and hit send. The MUA packages this message and forwards it to your outgoing mail server using SMTP.

Step 2 — The sending MTA processes the message

Your mail server's MTA receives the message and prepares to route it. It needs to figure out where the recipient's mail server is.

Step 3 — DNS lookup for the MX Record

This is a step most people never see. The MTA queries the DNS system for the recipient's domain, asking specifically for its MX Record (Mail Exchange Record).

The MX Record is essentially a directory entry that says: "For email addressed to this domain, send it to this server." Without it, the sending MTA has no idea where to deliver the message.

Step 4 — The sending MTA connects to the receiving MTA

Using the address returned by DNS, the sending MTA establishes a connection with the recipient's mail server and transfers the message via SMTP.

Step 5 — The receiving MDA stores the message

The receiving mail server's MDA takes the message, runs it through spam and security filters, then deposits it into the recipient's mailbox.

Step 6 — The recipient retrieves and reads the email (MUA)

The next time the recipient opens their email client, it connects to the server using POP3 or IMAP, fetches the message, and displays it.

The entire process, from step 1 to step 6, typically takes a few seconds.


The Protocols: SMTP, POP3, and IMAP

Email relies on three core protocols, each with a specific job.

SMTP (Simple Mail Transfer Protocol)

SMTP handles outgoing email. It is used in two places:

  • When your MUA sends a message to your mail server
  • When your mail server forwards the message to the recipient's mail server

SMTP is strictly for sending. It does not retrieve or store messages.

POP3 (Post Office Protocol v3)

POP3 handles incoming email by downloading messages from the server to your device.

The key behavior of POP3 is that messages are typically downloaded and removed from the server. This means your email lives on one device. If you check your inbox on your laptop, those messages may not be available on your phone.

POP3 is a reasonable choice when you use a single device and want your email stored locally, even without an internet connection.

IMAP (Internet Message Access Protocol)

IMAP also handles incoming email, but with a fundamentally different approach. Instead of downloading and removing messages, IMAP keeps everything synchronized on the server.

This means:

  • You can access your inbox from any device
  • Read/unread status, folder organization, and deletions sync across all devices
  • Your email is not tied to one machine

For anyone who checks email on a phone, laptop, and tablet, IMAP is the practical choice. It is why you can read an email on your phone and see it already marked as read when you open your laptop later.

POP3 vs IMAP at a Glance

AspectPOP3IMAP
Email storageDownloaded to deviceStays on server
Multi-device accessLimitedFull support
Server connectionBrief, for retrieval onlyActive, continuous sync
Best forSingle-device usersMulti-device users

Types of Mail Servers

Mail servers come in two fundamental deployment models: on-premise and cloud-based.

On-Premise Mail Server

An on-premise mail server is physically owned and operated by the organization. The hardware lives on-site, and the internal IT team manages everything: installation, updates, security, backups, and troubleshooting.

Advantages:

  • Complete control over data and configuration
  • No ongoing subscription costs after initial setup
  • Can operate independently of third-party services

Disadvantages:

  • Requires dedicated hardware and infrastructure
  • Needs a skilled IT team to maintain
  • Higher upfront cost and ongoing responsibility

Common software: Postfix, Sendmail, Zimbra, Microsoft Exchange Server

Cloud-Based Mail Server

A cloud-based mail server is hosted and managed by a third-party provider. The organization accesses the service through a web interface or email client, while the provider handles all the infrastructure.

Advantages:

  • No hardware to manage
  • Maintenance, security, and updates handled by the provider
  • Accessible from anywhere with an internet connection
  • Scales easily as the organization grows

Disadvantages:

  • Data is stored on external servers
  • Dependent on the provider's uptime and policies
  • Ongoing subscription costs

Examples: Google Workspace, Microsoft 365

Which Should You Choose?

For a small school or organization with limited IT resources, cloud-based is almost always the better starting point. The practical overhead of running your own mail server is substantial, and the benefits of full control only become meaningful at scale.

For larger organizations with strict data sovereignty requirements, an on-premise server or a hybrid approach may be necessary.


Mail Server Software Worth Knowing

Postfix

One of the most widely deployed MTAs in the world, particularly on Linux systems. Postfix is known for its security, reliability, and clean configuration structure. It is the default MTA on many Linux distributions and handles enormous volumes of email in production environments.

Sendmail

One of the oldest and most historically significant mail server programs. Sendmail was the dominant MTA for decades. It is highly configurable but has a reputation for complex configuration syntax. Many modern deployments have migrated to Postfix or other alternatives.

Microsoft Exchange Server

The enterprise standard in Windows environments. Exchange integrates email, calendars, contacts, and task management into a single system. It is tightly integrated with Microsoft 365 and Active Directory, making it a natural choice for organizations already invested in the Microsoft ecosystem.

Zimbra

An open-source mail server that includes webmail, calendaring, and collaboration tools. Zimbra is popular in educational institutions and mid-sized organizations looking for a full-featured alternative to Exchange without the licensing costs.


Security: What Can Go Wrong

Email is one of the most common vectors for cyberattacks. Understanding the threats is the first step toward defending against them.

Spam

Spam is unsolicited bulk email, typically sent for advertising or as a vehicle for other attacks. While a single spam email is harmless, it becomes a serious problem at scale. Spam clogs inboxes, wastes bandwidth, and often serves as the delivery mechanism for phishing attempts.

Defenses: Spam filters, blacklists, rate limiting, SPF/DKIM/DMARC records.

Phishing

Phishing is a social engineering attack delivered via email. The attacker crafts a convincing message that impersonates a trusted entity (a bank, an employer, a government agency) and tricks the recipient into revealing credentials or clicking a malicious link.

The attack that compromises an account almost always starts here.

Defenses: User education, multi-factor authentication, URL scanning, email authentication protocols.

Spoofing

Email spoofing is the forgery of the sender's address. An attacker can send an email that appears to come from kepala@smkn1.sch.id even without any access to that account. The recipient sees a trusted name and is more likely to act on the message.

Defenses: SPF records tell receiving servers which IP addresses are authorized to send email for a domain. DKIM adds a cryptographic signature to outgoing messages. DMARC ties these together and specifies what to do with messages that fail authentication.

Malware via Email

Malicious attachments and links remain one of the most effective malware delivery methods. A PDF, Word document, or ZIP file attached to an email can contain code that executes when opened.

Defenses: Attachment scanning, sandboxing, disabling macros by default, user education.


Autentikasi dan Enkripsi

Two concepts underpin almost all email security: authentication and encryption.

Authentication

Authentication answers the question: is this person who they say they are?

Username and password combinations are the baseline. Without them, anyone could access any inbox or send mail as any user. Stronger authentication adds a second factor, making account compromise significantly harder even if a password is stolen.

At the domain level, SPF, DKIM, and DMARC serve as authentication mechanisms for the mail server itself, verifying that messages claiming to be from your domain actually originated from your authorized servers.

Encryption (SSL/TLS)

When your email client connects to a mail server, the data traveling between them can be intercepted if the connection is unencrypted. SSL/TLS solves this by establishing an encrypted channel before any data is transmitted.

This protects:

  • Your login credentials
  • The content of your emails in transit
  • Metadata like subject lines and recipient addresses

A mail server without TLS is transmitting sensitive information in plain text across the network, readable by anyone with access to that traffic.


Real-World Applications

In Schools

A school mail server provides official email addresses like nama@smkn1.sch.id for teachers and staff. It centralizes communication, enables archiving for compliance, and maintains a professional identity separate from personal accounts. Announcements, report distributions, and administrative correspondence all benefit from a properly configured mail server.

In Companies

Corporate email is one of the primary channels for business communication. A company mail server manages employee accounts, enforces retention policies for legal compliance, integrates with directory services for authentication, and provides audit trails when disputes or investigations arise.

At ISPs

Internet Service Providers operate mail servers at massive scale, handling millions of accounts. Their systems manage delivery for customer email addresses, process support tickets, send billing notifications, and maintain reliability guarantees for business customers who depend on email uptime.


Summary

Email looks simple from the outside and is genuinely complex underneath. The key concepts to hold onto:

  • Mail servers are the infrastructure that makes email work, invisible to most users but central to everything.
  • MUA, MTA, and MDA are the three functional components in every email system, handling composition, transport, and delivery respectively.
  • SMTP sends email. POP3 downloads email to a single device. IMAP synchronizes email across multiple devices.
  • On-premise mail servers give you control at the cost of complexity. Cloud-based servers give you convenience at the cost of full ownership.
  • Spam, phishing, spoofing, and malware are the four main threats to email security. SPF, DKIM, DMARC, and TLS are the corresponding defenses.

Email has been around for over 50 years and remains one of the most important communication systems in existence. Understanding how it works is not just academic, it is practically useful for anyone building, administering, or securing networked systems.


Further Reading

  • RFC 5321 - SMTP Specification
  • RFC 3501 - IMAP Specification
  • Postfix Documentation
  • Google Workspace Admin Help

This article was written by Rejaka Abimanyu Susanto, a full-stack developer based in Yogyakarta, Indonesia. For more articles on networking and web development, visit rejaka.id.

Last modified: March 16, 2026
Built with Passion • Rejaka Portfolio