SMTP

E-mail

E-mail has three major components:

  • User agents
  • Mail servers
  • SMTP (Simple mail transfer protocol)

User Agents

User Agents compose, edit, read mail messages.

Mail servers

Mailbox contains incoming messages for user.
Message queue of outgoing mail messages.

SMTP

SMTP is a protocol between mail servers to send email messages.
SMTP has client SMTP server and server SMTP server.

Nowdays e-mail provides web-based interface with HTTP, but it's on top of SMTP and IMAP.

SMTP (RFC 5321)

Uses TCP to reliably transfer email messages on port 25.

  1. SMTP handshaking
    1. Server respond with 220
    2. Client sends HELLO
    3. Server respond with 250 Hello
  2. SMTP transfer of messages
    • Like HTTP, the commands are in ASCII text and the responses consist of a status code and a phrase.
    • Single dot "." indicates the end of a DATA section. (i.e. mail content)
  3. SMTP closure
    1. Client sends QUIT
    2. Server respond with 221

How does e-mail actually get sent?

  1. Alice uses User Agent to compose e-mail message.
  2. Alice's User Agent sends message to her mail server using SMTP.
  3. Alice's mail server place the message in message queue.
  4. Client side of SMTP at mail server opens TCP connection with Bob's mail server.
  5. SMTP client sends Alice's message to Bob's mail server.
  6. Bob's mail server places the message in mail box.
  7. Bob invokes User Agent to read message. (This does not use SMTP, it uses IMAP or POP3)

Comparison with HTTP

In HTTP:

  • Client pulls data from server.
  • Each object is encapsulated in its own response message.

In SMTP:

  • Client pushes data to server.
  • Multiple objects are sent in multipart message.

RFC 2822 defines syntax for e-mail message, but SMTP doesn't defines e-mail message syntax.
It can be plain ASCII, RTF (Rich Text Format), or any other format that can be shown better.