Email

So what’s the most popular application on the Internet? I don’t know, but I bet email is way up there.

Unit Goals

To get an understanding of what goes on behind the scenes of this whole email thing.

History

TODO

Architecture

TODO

SMTP

SMTP is the Simple Mail Transport Protocol. It:

Basic Model

This picture was stolen from RFC 2821:

smtp.gif

The server could be the ultimate destination for the mail, or be a relay, or be a gateway. What it is is irrelevant to describing the protocol.

Each command gets a reply. The dialogue is “lock-step, one at a time.”

Commands and replies are encoded in US-ASCII. They are not case-sensitive.

“No sending SMTP system is permitted to send envelope commands in any character set other than US-ASCII; receiving systems SHOULD reject such commands, normally using '500 syntax error - invalid character' replies.” But there is a service extension called 8BITMIME.

Commands

This is a summary of the basic commands. It does not show all the options. See RFC 2821 for complete details.

Hello and Extended Hello

HELO SP sendingdomain CRLF

EHLO SP sendingdomain CRLF

Sends the FQDN of the SMTP client, and the server responds to EHLO with the extensions that it supports.

Mail

MAIL SP FROM: reversepath CRLF

Identifies the sender mailbox

Recipient

RCPT SP TO: forwardpath CRLF

Identifies the recipients

Data

DATA CRLF

The server does not reply immediately after seeing this line. Instead the client follows this command with the message itself, which terminates with the five-octet sequence CR LF . CR LF

Reset

RSET CRLF

Aborts the current transaction but does not close the connection.

Verify

VRFY SP string CRLF

Asks server to confirm whether the arguement identifies a valid mailbox.

Expand

EXPN SP string CRLF

Asks server to confirm whether the arguement identifies a mailing list, and if so, to return the membership of the list.

Help

HELP [SP string] CRLF

No operation

NOOP CRLF

Quit

QUIT CRLF

Server must send an OK reply to this then close the connection.

Reply Codes

Every command must generate exactly one reply.

A reply is three digits followed by text. Some commands require the text and some do not. Usually the text is informative only.

Response can be single line

code SP text CRLF

or multiline

code - text CRLF
code - text CRLF
code - text CRLF
code SP text CRLF

These are all the codes specified in RFC 2821:

211System status, or system help reply
214 Help message (Information on how to use the receiver or the meaning of a particular non-standard command; this reply is useful only to the human user)
220<domain> Service ready
221 <domain> Service closing transmission channel
250Requested mail action okay, completed
251User not local; will forward to <forward-path>
252Cannot VRFY user, but will accept message and attempt delivery
354Start mail input; end with <CRLF>.<CRLF>
421<domain> Service not available, closing transmission channel (This may be a reply to any command if the service knows it must shut down)
450Requested mail action not taken: mailbox unavailable (e.g., mailbox busy)
451Requested action aborted: local error in processing
452Requested action not taken: insufficient system storage
500Syntax error, command unrecognized (This may include errors such as command line too long)
501Syntax error in parameters or arguments
502Command not implemented
503Bad sequence of commands
504Command parameter not implemented
550Requested action not taken: mailbox unavailable (e.g., mailbox not found, no access, or command rejected for policy reasons)
551User not local; please try <forward-path>
552Requested mail action aborted: exceeded storage allocation
553Requested action not taken: mailbox name not allowed (e.g., mailbox syntax incorrect)
554Transaction failed (Or, in the case of a connection-opening response, "No SMTP service here")

The numbering scheme: first digit is kind of response (good, bad, incomplete), second is kind of error.

1yz - positive preliminary reply (send whether to continue or abort)
2yz - positive completion reply (you succeeded, start a new command if you want)
3yz - positive intermediate reply (ok so far, send more info)
4yz - transient negative completion reply (try again)
5yz - permanent negative completeion reply (command failed)

x0z - syntax error
x1z - this is a reply to your request for information
x2z - reply related to connection
x5z - receiver status information

Example Sessions

Here is a simple session in which all the commands except RSET are used, a headerless message is sent, and a bad command is thrown in for fun. Oh yeah, and note you can pretend to be someone else by specifying that person's address in the MAIL FROM: command.

220-hawk.mail.pas.earthlink.net ESMTP Exim 3.33 #1 Sat, 08 Mar 2003 23:22:30 -0800
220-NO UCE. EarthLink does not authorize the use of its computers or network
220 equipment to deliver, accept, transmit, or distribute unsolicited e-mail.
EHLO lmu.edu
250-hawk.mail.pas.earthlink.net Hello 24-205-48-85.gln-eres.charterpipeline.net [24.205.48.85]
250-SIZE 10485760
250-PIPELINING
250 HELP
MAIL FROM:pdorin@lmu.edu
250 <pdorin@lmu.edu> is syntactically correct
RCPT TO:rtoal@lmu.edu
250 <rtoal@lmu.edu> is syntactically correct
HELP
214-Commands supported:
214-    HELO EHLO MAIL RCPT DATA AUTH
214     NOOP QUIT RSET HELP
DATA
354 Please start mail input.
hello
how
are
you
.
250 Mail queued for delivery.
NOOP
250 OK
VRFY president
252 VRFY not available
EXPN everybody
550 EXPN not available to 24-205-48-85.gln-eres.charterpipeline.net (lmu.edu) [24.205.48.85]
SQUIT
500 Unrecognized command
QUIT
221 Closing connection. Good bye.

Here's another session. There's a header this time.

220-avocet.mail.pas.earthlink.net ESMTP Exim 3.33 #1 Sat, 08 Mar 2003 23:42:41 -0800
220-NO UCE. EarthLink does not authorize the use of its computers or network
220 equipment to deliver, accept, transmit, or distribute unsolicited e-mail.
EHLO lmu.edu
250-avocet.mail.pas.earthlink.net Hello 24-205-48-85.gln-eres.charterpipeline.net [24.205.48.85]
250-SIZE 10485760
250-PIPELINING
250 HELP
MAIL FROM:rtoal@lmu.edu
250 <rtoal@lmu.edu> is syntactically correct
RCPT TO:rtoal@lmu.edu
250 <rtoal@lmu.edu> is syntactically correct
DATA
354 Please start mail input.
To: Whomever
From: <pdorin@lmu.edu>
Cc: Nobody
Subject: MAKE $$$$ FAST!!!!!!! THIS IS NOT SPAM

Ha ha ha - this message has
a virus. La la la la. ROTFL. LOL LOL.
SEND THIS MESSAGE TO EVERYONE YOU KNOW.
.
250 Mail queued for delivery.
QUIT
221 Closing connection. Good bye.

POP

Post Office Protocol

RFC 1939

"Intended to permit a workstation to dynamically access a maildrop on a server host in a useful fashion."

So simple you can go get your mail yourself by writing a small script or just using Telnet. Used basically for downloading messages from the server and deleting them; IMAP offers much more.

POP3 servers generally listen on port 110. It is a command-and-reply protocol.

Commands

Reply Codes

All replies have one of two formats:

IMAP

PGP

Summary

We’ve covered:

  • The history of email
  • Email architecture
  • One protocol for sending email: SMTP
  • Two protocols for managing one’s email: POP and IMAP
  • PGP for email privacy