Skip to content
BoKSA

06 – Electronic Mail: SMTP, IMAP, POP3 and Mail Security

06 – Electronic Mail: SMTP, IMAP, POP3 and Mail Security

Course: ICT Basic course · Level: introductory Book: Kurose & Ross, 9th ed., chapter 2.3 (electronic mail in the Internet)

Learning goals

After this article you can:

  • describe the parts of the Internet e-mail system: user agents, mail servers and protocols;
  • explain how SMTP delivers mail from server to server, step by step;
  • explain the difference between push (SMTP) and pull (IMAP, POP3) protocols;
  • explain the role of DNS MX records in mail delivery;
  • explain why e-mail is easy to fake and how SPF, DKIM and DMARC help.

1. The e-mail system

1
2
3
4
 Alice's            Alice's mail          Bob's mail             Bob's
 user agent         server                server                 user agent
 (Outlook) ──SMTP──► [outbox] ───SMTP────► [Bob's mailbox] ◄──IMAP── (phone app)
    587/465                       25                       993       or webmail (HTTPS)
Component Role Examples
User agent (MUA) read, write, send mail Outlook, Apple Mail, Thunderbird, Gmail app, webmail in the browser
Mail server (MTA) stores mailboxes, queues outgoing messages, delivers to other servers Microsoft Exchange Online, Gmail, Postfix, Exim
SMTP pushes mail: client → server and server → server
IMAP / POP3 / HTTPS pulls mail from the mailbox to the user

E-mail is asynchronous: Bob doesn't have to be online when Alice sends a message. His mail server keeps it.


2. SMTP – Simple Mail Transfer Protocol

  • One of the oldest Internet protocols (RFC 821, 1982; current version RFC 5321).
  • Runs over TCP.
  • Push protocol: the sending server opens a connection to the receiving server and pushes the message.
  • Text-based commands; originally only 7-bit ASCII. Attachments and non-English characters are encoded with MIME (e.g. Base64).

2.1 Which port?

Port Use
25 server ↔ server (MTA to MTA). Many ISPs block outgoing port 25 from home connections to stop spam from infected PCs
587 submission: your mail client → your own mail server, with STARTTLS and login
465 submission over implicit TLS (deprecated for years, but re-standardised in RFC 8314 and now recommended)

2.2 An SMTP dialogue

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
S: 220 mail.hva.nl ESMTP ready
C: EHLO mail.example.com
S: 250-mail.hva.nl Hello
S: 250-STARTTLS
S: 250 SIZE 52428800
C: MAIL FROM:<alice@example.com>
S: 250 OK
C: RCPT TO:<bob@hva.nl>
S: 250 OK
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: From: Alice <alice@example.com>
C: To: Bob <bob@hva.nl>
C: Subject: Meeting tomorrow
C:
C: Hi Bob, see you tomorrow!
C: .
S: 250 OK: queued as 4F2A1
C: QUIT
S: 221 Bye

Note the two levels of addresses: - the envelope (MAIL FROM, RCPT TO), which servers use for delivery; - the header (From:, To:) that you see in your mail client. Nothing in plain SMTP checks that these match, so this is how spoofing works.

2.3 How does the sending server find the receiving server?

Via DNS: it looks up the MX record (Mail eXchanger) of the recipient's domain.

1
2
$ dig MX hva.nl +short
10 hva-nl.u-v1.mx.microsoft.

So mail for @hva.nl is handled by Microsoft 365 (Exchange Online).

(MX records have a priority: lower number = preferred server.)


3. Mail access protocols: getting your mail

Protocol Port (encrypted) How it works Today
POP3 995 (110 plain) download and (usually) delete from the server Legacy: still supported, but not suitable when you read mail on several devices
IMAP 993 (143 plain) mail stays on the server; folders and read/unread status are synchronised across devices standard for mail apps
HTTPS (webmail) 443 the browser or app talks to the mail server via a web API most common: Gmail, Outlook on the web
Exchange ActiveSync / Microsoft Graph, JMAP 443 modern APIs for mobile apps ActiveSync is being phased out; JMAP (RFC 8620/8621) is a modern open alternative

Still in use? POP3 still exists, especially in older setups and for archiving, but most people use IMAP or webmail/apps. Microsoft and Google have switched off "basic authentication" (username + password) for IMAP/POP/SMTP and require OAuth 2.0 / modern authentication.


4. Try it yourself

  1. Look up the mail servers of a few domains:
    1
    2
    3
    4
    dig MX hva.nl +short
    dig MX gmail.com +short
    dig TXT hva.nl +short          # look for v=spf1 ...
    dig TXT _dmarc.hva.nl +short   # DMARC policy
    
  2. Open an e-mail in your mail client and look at the full headers ("Show original" in Gmail, "View message source" in Outlook). Find the Received: lines (the route the mail took) and the Authentication-Results: line (SPF/DKIM/DMARC results).
  3. Test a mail domain at https://www.internet.nl/ (mail test). Which modern standards are used?
  4. Send a mail to the address given at https://www.mail-tester.com/ and read the score report.

Check your understanding

  1. Which protocol pushes mail, and which protocols pull mail?
  2. Why does SMTP use DNS MX records?
  3. What is the difference between the envelope sender and the From: header?
  4. What is the main difference between POP3 and IMAP?
  5. Why do ISPs block outgoing port 25?

References

Book

  • Kurose & Ross, 9th ed., chapter 2.3 (Electronic mail in the Internet)

Videos

Articles and standards


Cyber Security

Why is this important for cyber security?

  • E-mail is the number one entry point for attacks. Phishing (fake mails that steal passwords), malicious attachments, and Business E-mail Compromise (a fake "CEO" or supplier asks to transfer money) cause enormous damage every year. Many ransomware attacks start with one e-mail.
  • SMTP was never designed to be secure. Without extra measures, anyone can send a mail with From: ceo@yourcompany.nl (spoofing), and mail between servers may travel unencrypted.
  • Mailboxes contain sensitive data (personal data, invoices, password-reset links). A hacked mailbox often gives access to many other accounts.

What can you do to make it safe?

As a domain owner / administrator: e-mail authentication

Standard What it does DNS record (example)
SPF – Sender Policy Framework lists which servers may send mail for your domain example.nl TXT "v=spf1 include:spf.protection.outlook.com -all"
DKIM – DomainKeys Identified Mail the sending server signs each mail with a private key; receivers check the signature with the public key from DNS selector1._domainkey.example.nl TXT "v=DKIM1; k=rsa; p=MIIB..."
DMARC tells receivers what to do when SPF/DKIM fail (none, quarantine, reject) and where to send reports _dmarc.example.nl TXT "v=DMARC1; p=reject; rua=mailto:dmarc@example.nl"

Since 2024, Google and Yahoo require SPF, DKIM and DMARC for bulk senders. Microsoft has added similar requirements for Outlook.com.

Encryption between servers - STARTTLS upgrades an SMTP connection to TLS, but by default it is opportunistic: an attacker can strip it. - MTA-STS (via HTTPS) and DANE (via DNSSEC) force servers to use TLS with a valid certificate. The Dutch government requires these standards ("pas-toe-of-leg-uit" list of Forum Standaardisatie).

Access to mailboxes - Use only encrypted ports (993, 995, 465/587 with TLS, 443). - Multi-factor authentication (MFA) on every mailbox; disable legacy/basic authentication.

As a user - Check the real sender address and links (hover before clicking); be suspicious of urgency ("pay today!"). - Never send passwords or verification codes by e-mail. Verify payment requests via another channel (phone). - Report phishing (in NL: forward to valse-email@fraudehelpdesk.nl, or use your organisation's report button). - For end-to-end encryption of the content: S/MIME or OpenPGP (e.g. Proton Mail uses OpenPGP).

Extra references