TCP/IP For Internet Administrators
Previous Section Previous Page Query/Search Next Page Next Section

Simple Mail Transfer Protocol (SMTP)

The Simple Mail Transfer Protocol (SMTP) is used to transfer messages across a network. It is defined in RFC 821. Under TCP/IP the SMTP protocol is implemented as an application layer protocol that uses Transmission Control Protocol (TCP) to establish a reliable connection between two systems. In a single session multiple mail and information messages can be transmitted in either direction across the link. One important feature of SMTP is its ability to relay mail across multiple environments. Mail may cross multiple networks using various media in its path from source to destination.

TCP uses a pair of ports numbers, one for source and one for destination, to identify each communications link. By default an SMTP client application will contact the remote server using TCP/IP application port number 25 as the destination port, and will select at random a port from the dynamic or private range for the source port number. The remote server will normally respond by contacting the client system using the private port number as the destination and port number 25 as the source.

In a typical SMTP session, a client system establishes a Telnet style conversation with a server, issues commands, and receives reply messages. Once the transmission channel is established, the client sends a MAIL command identifying the Sender of the mail message. If the server can accept mail it responds with an OK reply. The client then sends a RCPT command identifying the Recipient of the mail. If the server can accept mail for that recipient it responds with an OK reply; if not, it responds with a reply rejecting that recipient (but not the whole mail transaction). The client and server may negotiate several recipients for any individual mail message. When the recipients have been negotiated the client sends a DATA command, followed by the mail data, terminating with a special sequence. If the server successfully receives the mail data it responds with an OK reply. This dialog is purposely done in a lock-step, one-at-a-time sequence.

The RCPT identifies both the destination Host and the Mail Box of the recipient. This E-Mail address gives the mail box first, as a text name, followed by an “@”, followed by the domain name of the host (e.g. BillGates@Microsoft.Com). The MAIL command identifies the source host and mail box of the sender using the same format. When the same message is to be sent to multiple recipients, the SMTP specification encourages the data to be sent one time with multiple RCPT commands to identify the recipients.

SMTP provides a mechanism that allows mail to be sent directly from sender to recipient, or through intermediate hosts if there is no direct path from one to the other. Intermediate hosts may hold the message and try to pass it on towards the destination several times. If the message is not deliverable, a message to that effect is generated back to the sender.

The mail commands and replies have a rigid syntax. Commands are four character abbreviations that may be followed by arguments. Replies are a three digit numeric code followed by a text message. The numeric code is designed to make it easier for the reply messages to be processed by a program. The text of the reply message also indicates success or failure, or gives information in addition to the numeric code.

The SMTP protocol does require that all commands be implemented on all servers. There is a minimum command set that allows for compatibility between systems. For a full description of all SMTP commands and syntax, please see RFC 821. The following are commonly implemented SMTP commands:

HELO (Hello)
This command is used to identify the client system to the SMTP server. The argument is the host name of the client system. The SMTP server identifies itself to the client in the reply message. This command and an OK reply to it confirm that both the client and the server are ready to begin. The syntax of the Hello command is:

HELO hostname

MAIL (Mail)
This command is used to initiate a mail transaction in which a mail message is delivered to one or more recipient. The argument field contains a reverse path to the sender of the message. The reverse path contains the mail box and host of the sender, and may also have a list of multiple hosts. If the host part of the field contains multiple hosts, this is a list of the intermediate hosts in a reverse order path from the source to the current host. The syntax of the Mail command is:

MAIL FROM: source

RCPT (Recipient)
This command is used to identify an individual recipient of the mail message. Multiple recipients may be specified by multiple uses of this command. The argument specifies the mailbox and host of the recipient, and may also contain a list of multiple hosts. If the host part of the field contains multiple hosts, this is a source route and indicates that the mail must be relayed to the next host on the list. If the SMTP server does not implement the relay function, it may reply to the sender using the same message it would use for “Unknown Local User” (550). The format of the Recipient command is:

RCPT TO: recipient

DATA (Data)
This command notifies the server that the next lines are the text of the mail message. The server will record the following data until it receives a special terminating sequence. This sequence is normally the ASCII sequence (CRLF).(CRLF), a carriage-return linefeed followed by a period followed by another carriage-return linefeed. This sequence notifies the server that it should process the message. If for any reason it is necessary to send this unique sequence in an E-Mail message, it can be done by sending two period characters together. The extra period will be automatically stripped and the message will not be terminated.

RSET (Reset)
This command specifies that the current mail transaction is to be aborted. Any stored sender, recipients, and mail data is discarded, and all buffers and state tables cleared. The server responds with an OK reply.

VRFY (Verify)
This command asks the server to confirm that the argument identifies a user. If it is a user name, the full name of the user (if known) and the fully specified mailbox are returned. The syntax of the verify command is:

VRFY username

EXPN (Expand)
This command asks the server to confirm that the argument identifies a mailing list, and if so, to return the membership of that list. The full name of the users (if known) and the fully specified mailboxes are returned in a multi-line reply. The syntax of the Expand command is:

EXPN listname

HELP (Help)
This command causes the server to send a list of helpful information, normally a list of implemented commands. A command may be given as an argument to get more information on that specific command.

QUIT (Quit)
This command instructs the server to send an OK reply and then close the communication link.

An SMTP reply code consists of three digits, and is intended to make it easier for a program that is communicating with an FTP server to determine the result of the previous operation. The first digit tells whether the response if Good, Bad, or Incomplete. The second digit tells approximately what type of error occurred, and the third digit gives more specific information about the error.

The following is a list of standard reply codes:

211 System status, or system help reply

214 Help message

220 (domain) Service ready

221 (domain) Service closing transmission channel

250 Requested mail action okay, completed

251 User not local; will forward to (forward-path)

354 Start mail input; end with (CRLF).(CRLF)

421 (domain) Service not available,

450 Requested mail action not taken: mailbox unavailable

451 Requested action aborted: local error in processing

452 Requested action not taken: insufficient system storage

500 Syntax error, command unrecognized

501 Syntax error in parameters or arguments

502 Command not implemented

503 Bad sequence of commands

504 Command parameter not implemented

550 Requested action not taken: mailbox unavailable

551 User not local; please try “forward-path”

552 Requested mail action aborted: exceeded storage allocation

553 Requested action not taken: mailbox name not allowed

554 Transaction failed

If a user does not have an SMTP client application, or for the purposes of testing and troubleshooting, it is possible to use a Telnet client application to contact an SMTP server and send mail messages. This is done by Telnetting to port 25 and entering the commands by hand. For example, the following is an example of sending a test message to the Postmaster at the imaginary destination Mail.ZZZ.Com.

# telnet Mail.ZZZ.Com 25
Trying 192.168.10.1...
Connected to mail.zzz.com.
Escape character is '^]'.
220-zzz.com Sendmail 8.6.11/8.6.9 ready
220 ESMTP spoken here
HELO xyz.com
250 zzz.com Hello joe.xyz.com [192.168.99.7]
MAIL FROM: JoeS@XYZ.Com
250 JoeS@XYZ.Com... Sender ok
RCPT TO: Postmaster@XYZ.Com
250 Postmaster@XYZ.Com... Recipient ok
DATA
354 Enter mail, end with "."
This is a test
1
2
3
4
5
6
7
8
9
.
250 MAA27083 Message accepted for delivery
QUIT
221 zzz.com closing connection
Connection closed by foreign host.
#

For more information on the SMTP protocol, see RFC 821.

Previous Section Previous Page Query/Search Next Page Next Section