Electronics & Telecommunication (University) is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Email: SMTP, MIME, POP3 and IMAP

Email systems use SMTP to send mail between servers/clients, MIME to encode/structure non-text attachments, and POP3/IMAP for clients to retrieve and manage mail from a server.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Email is one of the oldest and still most used Internet applications. Engineers design and operate mail servers, gateways and clients; they must know how SMTP moves messages between servers, how MIME allows attachments and non-ASCII text, and how POP3 and IMAP let users retrieve and manage messages. These protocols appear in system design, debugging, security (spam filtering, DKIM/SPF), and client/server programming.

Key ideas

Exact SMTP transaction (commands the exam expects): a TCP connection is opened to server (default port 25 for MTA-to-MTA; 587 for message submission from MUA). On submission (port 587), clients typically issue STARTTLS (if offered) and authenticate with SMTP AUTH; implicit TLS submission on port 465 ("submissions", RFC 8314) is also common. The client issues EHLO (or HELO), then uses MAIL FROM: and one or more RCPT TO: commands, then DATA followed by the message content and a line with a single . to end the data. Finally QUIT closes the connection.

  • Definition: MIME (Multipurpose Internet Mail Extensions) — a standard that extends the original text-only email format to support multiple parts, non-ASCII text, and attachments. MIME does not replace SMTP; it provides headers and body encodings that are carried inside the SMTP DATA.

    Key MIME concepts: Content-Type (media type, e.g. text/plain, multipart/mixed), Content-Transfer-Encoding (e.g. 7bit, quoted-printable, base64), boundary parameter for multipart messages, and Content-Disposition (attachment vs inline).

  • Definition: POP3 (Post Office Protocol version 3) — a simple protocol for clients to download messages from a mail server. POP3 commonly uses three states: AUTHORIZATION, TRANSACTION, UPDATE. Assumption: client typically downloads messages and (optionally) deletes them from server.

    Typical POP3 flow: connect to port 110 (or 995 for POP3S), authenticate (USER / PASS), LIST and RETR to download, optional DELE to mark for deletion, QUIT to commit deletions.

  • Definition: IMAP (Internet Message Access Protocol) — a more feature-rich protocol designed for remote message access and server-side message manipulation. IMAP keeps messages on the server, supports multiple folders (mailboxes), flags (Seen, Recent, Answered), partial fetches and searching. IMAP typically uses port 143 (or 993 for IMAPS).

    IMAP model: the client opens a TCP connection, authenticates, SELECT a mailbox, then can SEARCH, FETCH (by sequence number or UID), STORE to change flags, COPY to copy messages, and EXPUNGE to remove messages marked for deletion. Unlike POP3, IMAP allows concurrent clients to view the same mailbox state.

  • SMTP reply codes: exact high-level definition: codes are 3-digit. First digit categories: 2yz success, 3yz intermediate (expect more input), 4yz transient failure (retry later), 5yz permanent failure. The second and third digits give protocol-specific meaning.

  • Mail flow (end-to-end): MUA -> (submission) -> MTA -> (MTA-to-MTA via DNS MX lookup) -> destination MTA -> (delivery to mailbox by MDA) -> MUA retrieves via POP3/IMAP. Diagram to draw: a row of boxes left-to-right labeled MUA (client), Submission MTA (MSA), DNS resolver (for MX), Destination MTA, MDA, final MUA; draw arrows and label ports: 587 (submission), 465 (submissions, implicit TLS), 25 (MTA-to-MTA), 110/995 (POP3), 143/993 (IMAP).

Formulas

Use these syntax lines to remember exact commands and headers.

EHLO domain.example.com — SMTP greeting asking for extended features. Domain is client's DNS name, or an address literal in brackets (e.g., [192.0.2.5]) if no domain name is available.

MAIL FROM:<user@example.com> — SMTP sender envelope.

RCPT TO:<recipient@example.net> — SMTP recipient envelope.

DATA — SMTP command to start message content; message ends with a line containing only .. Lines in the body that begin with a dot are dot-stuffed (an extra leading dot is added) for transparency, and a blank line must separate the message headers from the body (RFC 5322).

From: Display Name <user@example.com> — RFC 5322 header line (message header, not the envelope).

Content-Type: multipart/mixed; boundary="BOUNDARY_STRING" — MIME header to start a multipart body.

Content-Transfer-Encoding: base64 — MIME header indicating body is base64 encoded.

USER username and PASS password — basic POP3 authentication commands.

RETR n — POP3 retrieve message number n.

DELE n — POP3 mark message n for deletion in the TRANSACTION state; deletions are actually performed in the UPDATE state upon QUIT.

A001 LOGIN username password — IMAP tagged login command (tags are client-chosen tokens).

A002 SELECT INBOX — IMAP select mailbox to work with.

A003 FETCH 1 BODY[] — IMAP fetch full message with sequence number 1.

Worked examples

Example 1 — SMTP session trace (unsecured, exam-style):

Client connects to mail.example.com on port 25.

  1. Server greets: 220 mail.example.com ESMTP Postfix (server greeting).

  2. Client: EHLO client.example.org Server: several 250- capability lines, then 250 SIZE 10485760 etc.

  3. Client: MAIL FROM:<alice@client.example.org> Server: 250 2.1.0 Ok.

  4. Client: RCPT TO:<bob@example.net> Server: 250 2.1.5 Ok (or 550 5.1.1 User unknown if address invalid).

  5. Client: DATA Server: 354 End data with <CR><LF>.<CR><LF>

  6. Client sends message headers and body: From: Alice alice@client.example.org To: Bob bob@example.net Subject: Test

    Hello Bob, This is a test. . Server: 250 2.0.0 Ok: queued as 12345

  7. Client: QUIT Server: 221 2.0.0 Bye

What happens next (explain): the sending MTA queues the message and performs DNS MX lookup for example.net to find destination MTAs, then opens TCP to port 25 of a destination MTA and performs an SMTP MTA-to-MTA transfer (same command sequence between MTAs). The delivering MTA passes the message to an MDA that writes the message into the recipient's mailbox.

Example 2 — POP3 vs IMAP retrieval (trace and final state):

POP3 session (default port 110):

  1. Connect; server: +OK POP3 server ready
  2. USER alice -> +OK ; PASS secret -> +OK user successfully logged on
  3. LIST -> server lists 1 5120 (message 1 is 5120 octets)
  4. RETR 1 -> server sends full message lines ending with .
  5. If client wants message removed: DELE 1
  6. QUIT -> server: +OK dewey POP3 server signing off and deletes marked messages (UPDATE state).

IMAP session (default port 143), tagged commands shown:

  1. A001 LOGIN alice secret -> A001 OK LOGIN completed
  2. A002 SELECT INBOX -> * FLAGS (\Answered \Flagged \Deleted \Seen \Recent) and A002 OK [READ-WRITE] SELECT completed
  3. A003 SEARCH UNSEEN -> * SEARCH 2 5 meaning message sequence numbers 2 and 5 are unread.
  4. A004 FETCH 2 BODY[HEADER.FIELDS (SUBJECT FROM)] -> returns header fields only.
  5. A005 FETCH 2 BODY.PEEK[] -> returns full message without setting \Seen flag.
  6. A006 STORE 2 +FLAGS.SILENT (\Seen) -> mark message as seen. A006 OK.
  7. A007 LOGOUT -> * BYE then A007 OK LOGOUT completed.

Difference summary (explicit exam wording): POP3 downloads (simple mailbox copy, optional deletion) and is stateless across multiple clients; IMAP keeps state on the server (folders, flags), supports partial fetch and server-side search allowing multiple clients to share mailbox state.

Common mistakes

  • Confusing POP3 ports and IMAP ports (110 vs 143; secure variants 995 vs 993). Also mixing submission port 587 and MTA port 25.
  • Thinking MIME multipart/alternative will choose the first part; correct rule: present alternatives in increasing complexity (plain text first, HTML after); the client should pick the best it can display, usually the last it prefers — exam answers should state the ordering rule.
  • Using IMAP sequence numbers vs UIDs: sequence numbers change when messages are expunged; UIDs are persistent. Many students misuse them in protocol traces.

For your exam

Typical question types:

  • Definitions: give precise definitions for SMTP, MIME, POP3, IMAP and states.
  • Short notes: SMTP command sequence, MIME multipart types (mixed, alternative, related), POP3 state machine, IMAP capabilities and example commands.
  • Derivations/trace: show a full SMTP session with server replies, or a POP3/IMAP fetch trace.
  • Diagrams: draw mail flow from MUA to final MUA including ports and where DNS MX lookup happens.
  • Comparisons: POP3 vs IMAP (list advantages/disadvantages).

What a full-marks answer includes:

  • Clear definitions (bold term), correct default ports, exact SMTP command sequence with the DATA terminator, explanation of envelope vs header, example MIME headers and explanation of boundary use, POP3 states and IMAP mailbox/flag operations, and a short diagram or labelled steps for mail flow.

Quick check

  1. Which SMTP command starts the transfer of the message body?
  2. Which MIME header carries the information about attachment encoding?
  3. In POP3, what command permanently removes a message (after QUIT)?

Answers: 1) DATA 2) Content-Transfer-Encoding 3) DELE (deletion committed on QUIT)

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?