How Email Works Step by Step Explained

This tutorial explains the fundamentals and basic concepts of the email system. Learn what the UA, MSA, MTA, MDA, and AA are and how they work in the email system.

Essential components of a mail system

To learn how an email system works or how an email travels from source to destination, first, we need to understand the following essential components.

Email Client or Mail User Agent (UA)

An email client or a user agent is a software application or a program that is used to compose and read the email. On the sender side, it is used to compose and send the email. On the receiver side, it is used to read and reply to the received email. MS Outlook, macOS Mail, /bin/mail, Alpine, and Gmail are some examples of email client programs.

Mail Submission Agent (MSA)

MSA takes emails from the user agent and delivers them to a mail transfer agent. MSA was developed later in the email system. It was invented to reduce some burden from MTA.

If implemented, MSA sits between a user agent and a mail transfer agent. It secures the connection between UA and MTA by implementing encryption and authentication. Besides this, it can perform many more tasks based on its configuration, such as rewriting the email header and performing security checks.

Mail Delivery Agent (MDA)

MDA takes emails from MTA and delivers them to the message store. MDA does the opposite of MSA. Just like MSA, it was also invented to reduce the burden from MTA. Since MDA delivers emails to the local system, it is also known as LDA (local delivery agent). Same as MSA, several additional functionalities such as virus scanning and spam email filtering can be configured on MDA.

MSA and MDA are part of MTA. Whether they will be used or not depend on several factors such as volume of emails and security requirement. But if they are configured in MTA, we have to configure the user agent to communicate with them instead of MTA.

msa mta mda

Mail Transport Agent (MTA)

MTA is the backbone of an email system. It takes emails from UA or MSA, understands the recipient's address, and delivers them to their destination. MTA uses Simple Mail Transport Protocol (SMTP) for its operation.

Essential MTA operations are listed below.

Outgoing mail operation
  • Receive outgoing emails from UA and MSA
  • Understand the recipient’s addresses
  • If require, rewrite the addresses
  • Perform a DNS MX lookup to resolve the recipient’s address
  • If the recipient is directly accessible, forward the email to MDA
  • If the recipient is not directly accessible, forward the email to the next responsible MTA
Incoming mail operation
  • Receive incoming mails from other MTA
  • Understand the recipient’s addresses
  • If the recipient belongs to it, perform a virus scan and forward the email to MDA
  • If the recipient does not belong to it, forward the email to the next responsible MTA

Message stores

The message store is the location of the recipient's server or the computer where messages are delivered by MDA. Depending on the setting, messages can be stored in several formats, such as mbox and Maildir.

The mbox format

In this format, all messages are stored in a single file. To separate messages from each other, a special line is used between two messages.

The Maildir format

In this format, each message is stored in a separate file. This method is more convenient but it creates a lot of files.

The Maildir or the mbox format is convenient if the volume of email is low. These methods are usually used in small office networks or home networks. In a large network, a more advanced method such as a database is used to store the messages.

Access Agent (AA)

An access agent takes messages from the message store and delivers them to the email client or the user agent on the local device such as PC, laptop, tablet, smartphone, etc. Two protocols known as POP3 and IMAP are used by access agents to retrieve emails from the message store.


POP3 is a one-way protocol. It can only download messages in email clients from the message store. It does not tell the message box what users do with downloaded messages. Since the message store does not know what users do with the downloaded messages, it keeps locally stored messages intact or simply deletes them once they are downloaded.


IMAP is a two-way protocol. Besides downloading messages from the message store, it also updates the message store about the action which user performs on the downloaded messages. Since the message store knows the action which user takes on the downloaded messages, it automatically performs that action on locally stored messages to keep a similar copy of messages at both locations.

This protocol uses advanced techniques to download messages in email clients from the message store. It only downloads the header of mail. It downloads contents and attachments of mail only when the user reads the mail.

Differences between POP3 and IMAP

A user uses his laptop and smartphone to check emails. He downloaded all emails from the message store on the laptop. After downloading, he filtered and deleted unnecessary emails. If the user is using POP3, he has to perform the same filtration on the message store and on his smartphone again to keep the similar copy of emails on all locations. But if he is using IMAP, there is no need to repeat the same action on the message store and his smartphone. IMAP will automatically sync the user's activity across all devices.

The following image shows IMAP and POP3 settings in Gmail.

imap and pop example

How emails work

A user wants to send an email to several recipients, so he accesses the email client program and adds recipients in the To, CC, and BCC fields. He composes the email and clicks the Send button.

Based on the configuration, the email client program sends the email to either MSA or MTA for further processing. If MSA is configured, the email will be forwarded to it. If MSA is not configured, the email will be forwarded to MTA directly.

If MSA is configured and the email is received, it rewrites the header and performs several essential checks based on its configuration. Once all defined checks are done, it forwards the email to MTA.

If MSA is not configured and the email is directly received, MTA performs all MSA's tasks and checks the recipient's addresses. If recipients are more than one, it makes a separate copy of the email from the original email for each recipient.

MTA performs a DNS lookup to figure out the recipient's address. If the recipient's address is resolved, the MTA packs the email in an envelope and forwards it to the MTA which is authorized to receive the recipient's email.

At the recipient's MTA, if MDA is configured, MTA forwards the received email to it. Based on the configuration, MDA performs several security checks such as virus scanning and spam filtering. If MDA is not configured, MTA will perform all MDA's tasks. Once the pre-delivery checks are done, the email is forwarded to the message store.

Email remains in the message store until it is downloaded by the email client program. Once the email is downloaded, it will be available in the inbox of the email client program.

how email works step by step example

Parts of the email

An email contains three separate parts; envelope, header, and body.


An email is wrapped in an envelope by the first MTA. The first MTA puts all necessary information such as a delivery address, return address, and failed address on the envelope. Other MTAs use this information to forward or deliver the email. An envelope determines where the email will be delivered or to whom it will be returned if it can't be delivered.

Envelopes are internally used by MTAs to exchange emails between them. An envelope wrapped by the first MTA is unwrapped by the last MTA. An end-user never sends and receives an envelope with the email. Envelopes are invisible to users.


The header keeps a record of all information about the email such as from which address it was sent, the date and time when it was sent, by which MTA it was received and forwarded, and when it was delivered to the destination. Email client programs usually hide headers from the user while displaying the email contents.


The body contains the message text and attachments. Originally, emails were developed for text messages. Over time, they became so popular that a new standard known as MIME was developed to support several other formatting and encoding features.

MIME (Multipurpose Internet Mail Extensions) allows us to format and encode the email text with more advanced formatting techniques such as HTML. Since MIME uses its methods for formatting and encoding the mail text and attachment, the email client doesn't need to be running on the same platform or using the same operating system. Nearly, all modern email clients support and use MIME standards.

That's all for this tutorial. If you liked this tutorial, please share it with friends through your favorite social network.

ComputerNetworkingNotes Networking Tutorials How Email Works Step by Step Explained