CLASS="section" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" >

1.3. The SMTP Transaction

SMTP is the protocol that is used for mail delivery on the Internet. For a detailed description of the protocol, please refer to RFC 2821, as well as Dave Crocker's introduction to Internet Mail Architecture.

Mail deliveries involve an SMTP transaction between the connecting host (client) and the receiving host (server). For this discussion, the connecting host is the peer, and the receiving host is your server.

In a typical SMTP transaction, the client issues SMTP commands such as EHLO, MAIL FROM:, RCPT TO:, and DATA. Your server responds to each command with a 3-digit numeric code indicating whether the command was accepted (2xx), was subject to a temporary failure or restriction (4xx), or failed definitively/permanently (5xx), followed by some human readable explanation. A full description of these codes is included in RFC 2821.

A best case scenario SMTP transaction typically consists of the following relevant steps:

Table 1-1. Simple SMTP dialogue

ClientServer

Initiates a TCP connection to server.

Presents an SMTP banner - that is, a greeting that starts with the code 220 to indicate that it is ready to speak SMTP (or usually ESMTP, a superset of SMTP):
220 your.f.q.d.n ESTMP...

Introduces itself by way of an Hello command, either HELO (now obsolete) or EHLO, followed by its own Fully Qualified Domain Name:
EHLO peers.f.q.d.n

Accepts this greeting with a 250 response. If the client used the extended version of the Hello command (EHLO), your server knows that it is capable of handling multi-line responses, and so will normally send back several lines indicating the capabilities offered by your server:

250-your.f.q.d.n Hello ...
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-STARTTLS
250-AUTH
250 HELP

If the PIPELINING capability is included in this response, the client can from this point forward issue several commands at once, without waiting for the response to each one.

Starts a new mail transaction by specifying the Envelope Sender:
MAIL FROM:<sender@address>
		

Issues a 250 response to indicate that the sender is accepted.

Lists the Envelope Recipients of the message, one at a time, using the command:
RCPT TO:<receiver@address>

Issues a response to each command (2xx, 4xx, or 5xx, depending on whether delivery to this recipient was accepted, subject to a temporary failure, or rejected).

Issues a DATA command to indicate that it is ready to send the message.

Responds 354 to indicate that the command has been provisionally accepted.

Transmits the message, starting with RFC 2822 compliant header lines (such as: From:, To:, Subject:, Date:, Message-ID:). The header and the body are separated by an empty line. To indicate the end of the message, the client sends a single period (".") on a separate line.

Replies 250 to indicate that the message has been accepted.

If there are more messages to be delivered, issues the next MAIL FROM: command. Otherwise, it says QUIT, or in rare cases, simply disconnects.

Disconnects.