Kahibaro
Discord Login Register

SMTP fundamentals

Core Concepts of SMTP

Simple Mail Transfer Protocol (SMTP) is the standard protocol used to send email between servers and from mail clients to servers. For server administration, you mainly care about:

This chapter focuses on protocol fundamentals you’ll use when configuring and debugging MTAs like Postfix, Exim, or Sendmail (covered separately).

SMTP Roles: MUA, MTA, MSA, MDA

SMTP itself is primarily about server-to-server message transfer, but in practice you’ll encounter several roles:

SMTP fundamentals mainly concern MTA ↔ MTA and MUA/MSA ↔ MTA communication.

SMTP Ports and Security Modes

Common TCP ports used with SMTP:

Plain, STARTTLS, and Implicit TLS

Three common security patterns:

  1. Plain SMTP
    • Connection starts unencrypted.
    • No TLS; traffic is visible in transit.
    • Still common between MTAs on port 25, but opportunistic encryption (STARTTLS) is widely used.
  2. STARTTLS (Opportunistic or Enforced)
    • Connection starts plain, then upgraded to TLS using the STARTTLS command.
    • Used on ports 25 and 587.
    • Opportunistic: server offers STARTTLS; if not available, can fall back to plain (common between MTAs).
    • Enforced: client refuses to send mail unless TLS is negotiated (used for submission and high-security links).
  3. Implicit TLS (SMTPS)
    • Connection is encrypted from the first byte; no plain-text EHLO phase.
    • Commonly used on port 465.
    • Client expects TLS immediately after TCP connection.

As an admin, you will:

Basic SMTP Session Flow

A minimal SMTP session (without TLS, authentication, or extensions) looks like this:

  1. TCP connection to port 25 or 587.
  2. Server greeting:
    220 mail.example.com ESMTP
  3. Client identifies itself:
    • HELO client.example.org (old-style)
    • or EHLO client.example.org (extended SMTP; almost always used today)
  4. Envelope sender:
    • MAIL FROM:<sender@example.org>
  5. Envelope recipient(s):
    • RCPT TO:<user@example.com>
    • Repeat RCPT TO for multiple recipients.
  6. Transfer message data:
    • DATA
    • Server replies 354 End data with <CR><LF>.<CR><LF>
    • Client sends headers and body, then line with only a .
  7. Close the session:
    • QUIT
    • Server replies 221 Bye and closes connection.

The envelope (MAIL FROM / RCPT TO) is what SMTP uses for routing and delivery decisions, not the From: or To: headers inside the message body.

Core SMTP Commands

Understanding the small set of fundamental commands is essential for testing with tools like telnet or openssl s_client.

Connection and Capability

  250-mail.example.com
  250-PIPELINING
  250-SIZE 52428800
  250-STARTTLS
  250-AUTH PLAIN LOGIN
  250-ENHANCEDSTATUSCODES
  250-8BITMIME
  250 DSN

Envelope Handling

Message Data

    DATA
    354 End data with <CR><LF>.<CR><LF>
    From: Sender <sender@example.org>
    To: User <user@example.com>
    Subject: Test message
    This is the message body.
    .
    250 2.0.0 OK: queued as 12345

Session Termination

SMTP Response Codes

SMTP servers reply with 3-digit numeric codes and optional text. As an admin, you need to recognize common patterns.

Code Classes

The first digit indicates the category:

Common Status Codes

Typical codes you’ll see in logs and diagnostics:

Some MTAs also support enhanced status codes in the form x.y.z, for example:
550 5.1.1 User unknown

Relaying, Open Relays, and Anti-Abuse Basics

One of the most critical SMTP concepts for an admin is relaying.

What Is Relaying?

Relaying is when your server accepts mail for a non-local recipient and forwards it to another server. Examples:

Open Relay (What to Avoid)

An open relay is an SMTP server that will forward mail from any source to any destination without proper checks or authentication.

This is extremely dangerous because:

Correct Relay Policy

A typical sane relay policy:

Your MTA configuration (covered in the Postfix chapter) is where you enforce these rules, but understanding relay logic is part of SMTP fundamentals.

SMTP Envelope vs Message Headers

SMTP makes a critical distinction between:

Example:

  From: Marketing <noreply@example.org>
  To: Customer <user@example.net>

The bounce goes back to bounce-handler@example.org, not to noreply@example.org. This distinction matters when analyzing logs or configuring bounce handling.

Extended SMTP (ESMTP) and Common Extensions

EHLO introduces Extended SMTP, which allows new features. Key extensions you will see:

As an admin, you’ll see these in EHLO responses and may enable/disable them in your MTA configuration.

TLS and Certificate Considerations (Protocol View)

From an SMTP perspective (not full certificate management details):

You will configure keys and certificates in your MTA or TLS terminator, but understanding how SMTP uses them is part of the fundamentals.

Basic SMTP Testing from the Command Line

Even with advanced tools available, direct testing at the SMTP level is invaluable.

Unencrypted Testing (Local or Lab Use Only)

Using telnet or nc:

telnet mail.example.com 25
# or
nc mail.example.com 25

Then type commands manually:

EHLO test.local
MAIL FROM:<you@example.org>
RCPT TO:<user@example.com>
DATA
From: You <you@example.org>
To: User <user@example.com>
Subject: Test
Hello from raw SMTP.
.
QUIT

Testing STARTTLS

Use openssl s_client:

openssl s_client -connect mail.example.com:587 -starttls smtp

After TLS is established, issue EHLO and other SMTP commands over the encrypted channel.

These tests help you verify:

SMTP, Queues, and Delivery Attempts (High-Level View)

While actual queue management is part of MTA-specific chapters, SMTP fundamentals explain why queues exist:

Understanding that SMTP clients differentiate between 4xx (retry later) and 5xx (fail now) is fundamental to reading and interpreting mail logs and behavior.

Summary of Key SMTP Fundamentals for Admins

Subsequent chapters will build on these fundamentals to configure specific SMTP servers (like Postfix), handle IMAP/POP3 access, and implement spam and security controls.

Views: 27

Comments

Please login to add a comment.

Don't have an account? Register now!