Network and System AdministrationUnit 68 min read
Email Protocols: SMTP, POP3, IMAP – Workflows, Security & Configurations
Unit 6 of Network and System Administration explores how email services function using SMTP (sending), POP3/IMAP (receiving), their message formats, security mechanisms, and real-world configurations in Linux servers like Apache/Nginx integration.
TAKEAWAYS:
- SMTP uses port 25/587 for store-and-forward email delivery via handshake phases (greeting, MAIL FROM, RCPT TO, DATA, QUIT).
- POP3 (port 110) downloads emails once and deletes them from the server, while IMAP (port 143) keeps them synchronized across devices.
- Email headers contain envelope vs. message headers, with critical fields like
From,To,Subject, andMIME-Versionfor attachments. - Security threats include spam, phishing, and MITM attacks, mitigated by TLS/SSL, SPF, DKIM, and DMARC.
- Linux servers configure email services using Postfix (SMTP) + Dovecot (POP3/IMAP) with
/etc/postfix/main.cfand/etc/dovecot/dovecot.conf.
1. Email Services Overview: Protocols and Roles
Email systems rely on three core protocols:
- SMTP (Simple Mail Transfer Protocol): Sends emails between servers (port 25 or 587 for submission).
- POP3 (Post Office Protocol v3): Downloads emails once to a client (port 110).
- IMAP (Internet Message Access Protocol): Syncs emails across devices (port 143 or 993 for SSL).
2. SMTP: How Emails Travel Across the Internet
SMTP operates in four phases (with TLS encryption for security):
- Greeting: Client → Server (
HELO example.com) - Mail Sender:
MAIL FROM: <sender@example.com> - Recipient:
RCPT TO: <recipient@domain.com> - Data Transfer:
DATA→ Email body →QUIT
SMTP Message Format
Emails consist of:
- Envelope Headers (hidden, used by servers):
Return-Path:Received: from ... by ...
- Message Headers (visible to users):
From: sender@example.comTo: recipient@example.comSubject: Hello!MIME-Version: 1.0(for attachments)
Worked Example: Sending an Email via SMTP
Scenario: User sends an email from alice@tu.edu.np to bob@pu.edu.np using eSewa’s SMTP server.
- Alice’s device connects to
smtp.esewa.com.np:587. - SMTP handshake:
Client: EHLO alice.com Server: 250-hello Client: MAIL FROM: <alice@tu.edu.np> Server: 250 OK Client: RCPT TO: <bob@pu.edu.np> Server: 250 OK Client: DATA Server: 354 Start mail input Client: Subject: Payment Confirmation Client: From: alice@tu.edu.np Client: To: bob@pu.edu.np Client: . Server: 250 OK Client: QUIT
3. POP3 vs. IMAP: Retrieving Emails
| Feature | POP3 (Port 110) | IMAP (Port 143) |
|---|---|---|
| Sync | Downloads emails once, deletes from server | Syncs across devices, keeps server copy |
| Offline Use | Works offline after download | Requires connection to sync |
| Storage | Limited by client device | Limited by server storage |
| Use Case | Basic email (e.g., Ncell’s old email) | Multiple devices (e.g., Gmail, WhatsApp Business) |
POP3 Workflow
- Client connects to server (
USER alice,PASS secret). - Server lists emails (
LIST). - Client downloads (
RETR 1). - Server deletes (unless configured to keep).
IMAP Workflow
- Client connects (
LOGIN alice secret). - Server lists folders (
LIST "" "*"). - Client selects folder (
SELECT INBOX). - Server syncs changes (e.g., flags, deletions).
4. Security in Email Services
Threats
- Spam: Unsolicited emails (e.g., Daraz promotions).
- Phishing: Fake emails (e.g., Nepal Rastra Bank scams).
- MITM (Man-in-the-Middle): Eavesdropping on unencrypted SMTP.
Mitigations
| Method | Description | Example in Nepal |
|---|---|---|
| TLS/SSL | Encrypts SMTP (port 465 or 587) | eSewa’s secure payment emails |
| SPF | Verifies sender’s IP is authorized | Ncell’s email SPF records |
| DKIM | Adds digital signature to emails | Khalti’s transaction alerts |
| DMARC | Policies for failed SPF/DKIM checks | Nepal Stock Exchange (NEPSE) emails |
5. Configuring Email Services on Linux
Installing Postfix (SMTP) and Dovecot (POP3/IMAP)
- Install packages (Ubuntu/Debian):
sudo apt update sudo apt install postfix dovecot-core - Configure Postfix (
/etc/postfix/main.cf):myhostname = mail.example.com mydomain = example.com myorigin = $mydomain inet_interfaces = all - Configure Dovecot (
/etc/dovecot/dovecot.conf):protocols = imap pop3 ssl = required - Restart services:
sudo systemctl restart postfix dovecot
6. Real-World Applications
In the Real World
- eSewa: Uses SMTP with TLS to send payment confirmations securely.
- Khalti: Relies on DKIM and DMARC to prevent spoofed transaction emails.
- Ncell: Older systems used POP3 for basic email retrieval; newer ones use IMAP for sync.
- Nepal Stock Exchange (NEPSE): Employs SPF records to authenticate shareholder emails.
Worked Example: NTC’s Email Relay Nepal Telecom Company (NTC) uses an SMTP relay to route internal emails between departments.
- Internal Email Flow:
user1@ntc.gov.np→smtp.ntc.gov.np:25→ Relay server →user2@ntc.gov.np.
- Security:
- SPF: Ensures only NTC’s servers send emails.
- TLS: Encrypts emails in transit.
Exam Tip
- SMTP Questions:
- Memorize the 4-phase handshake (
HELO,MAIL FROM,RCPT TO,DATA). - Know ports: 25 (SMTP), 587 (submission), 465 (SMTPS).
- Memorize the 4-phase handshake (
- POP3 vs. IMAP:
- POP3 = download-and-delete; IMAP = sync.
- Expect comparison tables in short-answer questions.
- Security:
- SPF/DKIM/DMARC are often asked together. Draw their flowchart.
- Linux Config:
- Be ready to edit
/etc/postfix/main.cfor/etc/dovecot/dovecot.confin practicals.
- Be ready to edit
- Real-World Scenarios:
- Relate eSewa/Khalti emails to TLS/SPF in descriptive questions.
Key Formula to Remember:
SMTP Ports:
- 25 (SMTP), 587 (Submission), 465 (SMTPS)
POP3/IMAP Ports:
- 110 (POP3), 143 (IMAP), 993 (IMAPS), 995 (POP3S)
Based on the TU BIT syllabus for Network and System Administration (BIT451), unit 6.
Discussion
Loading…