RFC2821 - Simple Mail Transfer Protocol(3)

时间:2005-02-16 来源: 作者: 点击:次
by machines. In the general case, the text may be receiver dependent and context dependent, so there are likely to be varying texts for each reply code. A discussion of the theory of reply codes is g
  
by machines. In the general case, the text may be receiver dependent
and context dependent, so there are likely to be varying texts for
each reply code. A discussion of the theory of reply codes is given
in section 4.2.1. Formally, a reply is defined to be the sequence: a
three-digit code, <SP>, one line of text, and <CRLF>, or a multiline
reply (as defined in section 4.2.1). Since, in violation of this
specification, the text is sometimes not sent, clients which do not
receive it SHOULD be prepared to process the code alone (with or
without a trailing space character). Only the EHLO, EXPN, and HELP
commands are expected to result in multiline replies in normal
circumstances, however, multiline replies are allowed for any
command.

In ABNF, server responses are:

Greeting = "220 " Domain [ SP text ] CRLF
Reply-line = Reply-code [ SP text ] CRLF

where "Greeting" appears only in the 220 response that announces that
the server is opening its part of the connection.

An SMTP server SHOULD send only the reply codes listed in this
document. An SMTP server SHOULD use the text shown in the examples
whenever appropriate.

An SMTP client MUST determine its actions only by the reply code, not
by the text (except for the "change of address" 251 and 551 and, if
necessary, 220, 221, and 421 replies); in the general case, any text,
including no text at all (although senders SHOULD NOT send bare
codes), MUST be acceptable. The space (blank) following the reply
code is considered part of the text. Whenever possible, a receiver-
SMTP SHOULD test the first digit (severity indication) of the reply
code.

The list of codes that appears below MUST NOT be construed as
permanent. While the addition of new codes should be a rare and
significant activity, with supplemental information in the textual
part of the response being preferred, new codes may be added as the
result of new Standards or Standards-track specifications.
Consequently, a sender-SMTP MUST be prepared to handle codes not
specified in this document and MUST do so by interpreting the first
digit only.

4.2.1 Reply Code Severities and Theory

The three digits of the reply each have a special significance. The
first digit denotes whether the response is good, bad or incomplete.
An unsophisticated SMTP client, or one that receives an unexpected
code, will be able to determine its next action (proceed as planned,
redo, retrench, etc.) by examining this first digit. An SMTP client
that wants to know approximately what kind of error occurred (e.g.,
mail system error, command syntax error) may examine the second
digit. The third digit and any supplemental information that may be
present is reserved for the finest gradation of information.

There are five values for the first digit of the reply code:

1yz Positive Preliminary reply
The command has been accepted, but the requested action is being
held in abeyance, pending confirmation of the information in this
reply. The SMTP client should send another command specifying
whether to continue or abort the action. Note: unextended SMTP
does not have any commands that allow this type of reply, and so
does not have continue or abort commands.

2yz Positive Completion reply
The requested action has been successfully completed. A new
request may be initiated.

3yz Positive Intermediate reply
The command has been accepted, but the requested action is being
held in abeyance, pending receipt of further information. The
SMTP client should send another command specifying this
information. This reply is used in command sequence groups (i.e.,
in DATA).

4yz Transient Negative Completion reply
The command was not accepted, and the requested action did not
occur. However, the error condition is temporary and the action
may be requested again. The sender should return to the beginning
of the command sequence (if any). It is difficult to assign a
meaning to "transient" when two different sites (receiver- and

sender-SMTP agents) must agree on the interpretation. Each reply
in this category might have a different time value, but the SMTP
client is encouraged to try again. A rule of thumb to determine
whether a reply fits into the 4yz or the 5yz category (see below)
is that replies are 4yz if they can be successful if repeated
without any change in command form or in properties of the sender
or receiver (that is, the command is repeated identically and the
receiver does not put up a new implementation.)

5yz Permanent Negative Completion reply
The command was not accepted and the requested action did not
occur. The SMTP client is discouraged from repeating the exact
request (in the same sequence). Even some "permanent" error
conditions can be corrected, so the human user may want to direct
the SMTP client to reinitiate the command sequence by direct
action at some point in the future (e.g., after the spelling has
been changed, or the user has altered the account status).

The second digit encodes responses in specific categories:

x0z Syntax: These replies refer to syntax errors, syntactically
correct commands that do not fit any functional category, and
unimplemented or superfluous commands.

x1z Information: These are replies to requests for information,
such as status or help.

x2z Connections: These are replies referring to the transmission
channel.

x3z Unspecified.

x4z Unspecified.

x5z Mail system: These replies indicate the status of the receiver
mail system vis-a-vis the requested transfer or other mail system
action.

The third digit gives a finer gradation of meaning in each category
specified by the second digit. The list of replies illustrates this.
Each reply text is recommended rather than mandatory, and may even
change according to the command with which it is associated. On the
other hand, the reply codes must strictly follow the specifications
in this section. Receiver implementations should not invent new
codes for slightly different situations from the ones described here,
but rather adapt codes already defined.

For example, a command such as NOOP, whose successful execution does
not offer the SMTP client any new information, will return a 250
reply. The reply is 502 when the command requests an unimplemented
non-site-specific action. A refinement of that is the 504 reply for
a command that is implemented, but that requests an unimplemented
parameter.

The reply text may be longer than a single line; in these cases the
complete text must be marked so the SMTP client knows when it can
stop reading the reply. This requires a special format to indicate a
multiple line reply.

The format for multiline replies requires that every line, except the
last, begin with the reply code, followed immediately by a hyphen,
"-" (also known as minus), followed by text. The last line will
begin with the reply code, followed immediately by <SP>, optionally
some text, and <CRLF>. As noted above, servers SHOULD send the <SP>
if subsequent text is not sent, but clients MUST be prepared for it
to be omitted.

For example:

123-First line
123-Second line
123-234 text beginning with numbers
123 The last line

In many cases the SMTP client then simply needs to search for a line
beginning with the reply code followed by <SP> or <CRLF> and ignore
all preceding lines. In a few cases, there is important data for the
client in the reply "text". The client will be able to identify
these cases from the current context.

4.2.2 Reply Codes by Function Groups

500 Syntax error, command unrecognized
(This may include errors such as command line too long)
501 Syntax error in parameters or arguments
502 Command not implemented (see section 4.2.4)
503 Bad sequence of commands
504 Command parameter not implemented

211 System 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
421 <domain> Service not available, closing transmission channel
(This may be a reply to any command if the service knows it
must shut down)

250 Requested mail action okay, completed
251 User not local; will forward to <forward-path>
(See section 3.4)
252 Cannot VRFY user, but will accept message and attempt
delivery
(See section 3.5.3)
450 Requested mail action not taken: mailbox unavailable
(e.g., mailbox busy)
550 Requested action not taken: mailbox unavailable
(e.g., mailbox not found, no access, or command rejected
for policy reasons)
451 Requested action aborted: error in processing
551 User not local; please try <forward-path>
(See section 3.4)
452 Requested action not taken: insufficient system storage
552 Requested mail action aborted: exceeded storage allocation
553 Requested action not taken: mailbox name not allowed
(e.g., mailbox syntax incorrect)
354 Start mail input; end with <CRLF>.<CRLF>
554 Transaction failed (Or, in the case of a connection-opening
response, "No SMTP service here")

4.2.3 Reply Codes in Numeric Order

211 System 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
250 Requested mail action okay, completed
251 User not local; will forward to <forward-path>
(See section 3.4)
252 Cannot VRFY user, but will accept message and attempt
delivery
(See section 3.5.3)

354 Start 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)
450 Requested mail action not taken: mailbox unavailable
(e.g., mailbox busy)
451 Requested action aborted: local error in processing
452 Requested action not taken: insufficient system storage
500 Syntax error, command unrecognized
(This may include errors such as command line too long)
501 Syntax error in parameters or arguments
502 Command not implemented (see section 4.2.4)
503 Bad sequence of commands
504 Command parameter not implemented
550 Requested action not taken: mailbox unavailable
(e.g., mailbox not found, no access, or command rejected
for policy reasons)
551 User not local; please try <forward-path>
(See section 3.4)
552 Requested mail action aborted: exceeded storage allocation
553 Requested action not taken: mailbox name not allowed
(e.g., mailbox syntax incorrect)
554 Transaction failed (Or, in the case of a connection-opening
response, "No SMTP service here")

4.2.4 Reply Code 502

Questions have been raised as to when reply code 502 (Command not
implemented) SHOULD be returned in preference to other codes. 502
SHOULD be used when the command is actually recognized by the SMTP
server, but not implemented. If the command is not recognized, code
500 SHOULD be returned. Extended SMTP systems MUST NOT list
capabilities in response to EHLO for which they will return 502 (or
500) replies.

4.2.5 Reply Codes After DATA and the Subsequent <CRLF>.<CRLF>

When an SMTP server returns a positive completion status (2yz code)
after the DATA command is completed with <CRLF>.<CRLF>, it accepts
responsibility for:

- delivering the message (if the recipient mailbox exists), or

- if attempts to deliver the message fail due to transient
conditions, retrying delivery some reasonable number of times at
intervals as specified in section 4.5.4.

- if attempts to deliver the message fail due to permanent
conditions, or if repeated attempts to deliver the message fail
due to transient conditions, returning appropriate notification to
the sender of the original message (using the address in the SMTP
MAIL command).

When an SMTP server returns a permanent error status (5yz) code after
the DATA command is completed with <CRLF>.<CRLF>, it MUST NOT make
any subsequent attempt to deliver that message. The SMTP client
retains responsibility for delivery of that message and may either
return it to the user or requeue it for a subsequent attempt (see
section 4.5.4.1).

The user who originated the message SHOULD be able to interpret the
return of a transient failure status (by mail message or otherwise)
as a non-delivery indication, just as a permanent failure would be
interpreted. I.e., if the client SMTP successfully handles these
conditions, the user will not receive such a reply.

When an SMTP server returns a permanent error status (5yz) code after
the DATA command is completely with <CRLF>.<CRLF>, it MUST NOT make
any subsequent attempt to deliver the message. As with temporary
error status codes, the SMTP client retains responsibility for the
message, but SHOULD not again attempt delivery to the same server
without user review and intervention of the message.

4.3 Sequencing of Commands and Replies

4.3.1 Sequencing Overview

The communication between the sender and receiver is an alternating
dialogue, controlled by the sender. As such, the sender issues a
command and the receiver responds with a reply. Unless other
arrangements are negotiated through service extensions, the sender
MUST wait for this response before sending further commands.

One important reply is the connection greeting. Normally, a receiver
will send a 220 "Service ready" reply when the connection is
completed. The sender SHOULD wait for this greeting message before
sending any commands.

Note: all the greeting-type replies have the official name (the
fully-qualified primary domain name) of the server host as the first
word following the reply code. Sometimes the host will have no
meaningful name. See 4.1.3 for a discussion of alternatives in these
situations.

For example,

220 ISIF.USC.EDU Service ready
or
220 mail.foo.com SuperSMTP v 6.1.2 Service ready
or
220 [10.0.0.1] Clueless host service ready

The table below lists alternative success and failure replies for
each command. These SHOULD be strictly adhered to: a receiver may
substitute text in the replies, but the meaning and action implied by
the code numbers and by the specific command reply sequence cannot be
altered.

4.3.2 Command-Reply Sequences

Each command is listed with its usual possible replies. The prefixes
used before the possible replies are "I" for intermediate, "S" for
success, and "E" for error. Since some servers may generate other
replies under special circumstances, and to allow for future
extension, SMTP clients SHOULD, when possible, interpret only the
first digit of the reply and MUST be prepared to deal with
unrecognized reply codes by interpreting the first digit only.
Unless extended using the mechanisms described in section 2.2, SMTP
servers MUST NOT transmit reply codes to an SMTP client that are
other than three digits or that do not start in a digit between 2 and
5 inclusive.

These sequencing rules and, in principle, the codes themselves, can
be extended or modified by SMTP extensions offered by the server and
accepted (requested) by the client.

In addition to the codes listed below, any SMTP command can return
any of the following codes if the corresponding unusual circumstances
are encountered:

500 For the "command line too long" case or if the command name was
not recognized. Note that producing a "command not recognized"
error in response to the required subset of these commands is a
violation of this specification.

501 Syntax error in command or arguments. In order to provide for
future extensions, commands that are specified in this document as
not accepting arguments (DATA, RSET, QUIT) SHOULD return a 501
message if arguments are supplied in the absence of EHLO-
advertised extensions.

421 Service shutting down and closing transmission channel

Specific sequences are:

CONNECTION ESTABLISHMENT
S: 220
E: 554
EHLO or HELO
S: 250
E: 504, 550
MAIL
S: 250
E: 552, 451, 452, 550, 553, 503
RCPT
S: 250, 251 (but see section 3.4 for discussion of 251 and 551)
E: 550, 551, 552, 553, 450, 451, 452, 503, 550
DATA
I: 354 -> data -> S: 250
E: 552, 554, 451, 452
E: 451, 554, 503
RSET
S: 250
VRFY
S: 250, 251, 252
E: 550, 551, 553, 502, 504
EXPN
S: 250, 252
E: 550, 500, 502, 504
HELP
S: 211, 214
E: 502, 504
NOOP
S: 250
QUIT
S: 221

4.4 Trace Information

When an SMTP server receives a message for delivery or further
processing, it MUST insert trace ("time stamp" or "Received")
information at the beginning of the message content, as discussed in
section 4.1.1.4.

This line MUST be structured as follows:

- The FROM field, which MUST be supplied in an SMTP environment,
SHOULD contain both (1) the name of the source host as presented
in the EHLO command and (2) an address literal containing the IP
address of the source, determined from the TCP connection.

- The ID field MAY contain an "@" as suggested in RFC822, but this
is not required.

- The FOR field MAY contain a list of <path> entries when multiple
RCPT commands have been given. This may raise some security
issues and is usually not desirable; see section 7.2.

An Internet mail program MUST NOT change a Received: line that was
previously added to the message header. SMTP servers MUST prepend
Received lines to messages; they MUST NOT change the order of
existing lines or insert Received lines in any other location.

As the Internet grows, comparability of Received fields is important
for detecting problems, especially slow relays. SMTP servers that
create Received fields SHOULD use explicit offsets in the dates
(e.g., -0800), rather than time zone names of any type. Local time
(with an offset) is preferred to UT when feasible. This formulation
allows slightly more information about local circumstances to be
specified. If UT is needed, the receiver need merely do some simple
arithmetic to convert the values. Use of UT loses information about
the time zone-location of the server. If it is desired to supply a
time zone name, it SHOULD be included in a comment.

When the delivery SMTP server makes the "final delivery" of a
message, it inserts a return-path line at the beginning of the mail
data. This use of return-path is required; mail systems MUST support
it. The return-path line preserves the information in the <reverse-
path> from the MAIL command. Here, final delivery means the message
has left the SMTP environment. Normally, this would mean it had been
delivered to the destination user or an associated mail drop, but in
some cases it may be further processed and transmitted by another
mail system.

It is possible for the mailbox in the return path to be different
from the actual sender's mailbox, for example, if error responses are
to be delivered to a special error handling mailbox rather than to
the message sender. When mailing lists are involved, this
arrangement is common and useful as a means of directing errors to
the list maintainer rather than the message originator.

The text above implies that the final mail data will begin with a
return path line, followed by one or more time stamp lines. These
lines will be followed by the mail data headers and body [32].

It is sometimes difficult for an SMTP server to determine whether or
not it is making final delivery since forwarding or other operations
may occur after the message is accepted for delivery. Consequently,

any further (forwarding, gateway, or relay) systems MAY remove the
return path and rebuild the MAIL command as needed to ensure that
exactly one such line appears in a delivered message.

A message-originating SMTP system SHOULD NOT send a message that
already contains a Return-path header. SMTP servers performing a
relay function MUST NOT inspect the message data, and especially not
to the extent needed to determine if Return-path headers are present.
SMTP servers making final delivery MAY remove Return-path headers
before adding their own.

The primary purpose of the Return-path is to designate the address to
which messages indicating non-delivery or other mail system failures
are to be sent. For this to be unambiguous, exactly one return path
SHOULD be present when the message is delivered. Systems using RFC
822 syntax with non-SMTP transports SHOULD designate an unambiguous
address, associated with the transport envelope, to which error
reports (e.g., non-delivery messages) should be sent.

Historical note: Text in RFC822 that appears to contradict the use
of the Return-path header (or the envelope reverse path address from
the MAIL command) as the destination for error messages is not
applicable on the Internet. The reverse path address (as copied into
the Return-path) MUST be used as the target of any mail containing
delivery error messages.

In particular:

- a gateway from SMTP->elsewhere SHOULD insert a return-path header,
unless it is known that the "elsewhere" transport also uses
Internet domain addresses and maintains the envelope sender
address separately.

- a gateway from elsewhere->SMTP SHOULD delete any return-path
header present in the message, and either copy that information to
the SMTP envelope or combine it with information present in the
envelope of the other transport system to construct the reverse
path argument to the MAIL command in the SMTP envelope.

The server must give special treatment to cases in which the
processing following the end of mail data indication is only
partially successful. This could happen if, after accepting several
recipients and the mail data, the SMTP server finds that the mail
data could be successfully delivered to some, but not all, of the
recipients. In such cases, the response to the DATA command MUST be
an OK reply. However, the SMTP server MUST compose and send an
"undeliverable mail" notification message to the originator of the
message.

A single notification listing all of the failed recipients or
separate notification messages MUST be sent for each failed
recipient. For economy of processing by the sender, the former is
preferred when possible. All undeliverable mail notification
messages are sent using the MAIL command (even if they result from
processing the obsolete SEND, SOML, or SAML commands) and use a null
return path as discussed in section 3.7.

The time stamp line and the return path line are formally defined as
follows:

Return-path-line = "Return-Path:" FWS Reverse-path <CRLF>

Time-stamp-line = "Received:" FWS Stamp <CRLF>

Stamp = From-domain By-domain Opt-info ";" FWS date-time

; where "date-time" is as defined in [32]
; but the "obs-" forms, especially two-digit
; years, are prohibited in SMTP and MUST NOT be used.

From-domain = "FROM" FWS Extended-Domain CFWS

By-domain = "BY" FWS Extended-Domain CFWS

Extended-Domain = Domain /
( Domain FWS "(" TCP-info ")" ) /
( Address-literal FWS "(" TCP-info ")" )

TCP-info = Address-literal / ( Domain FWS Address-literal )
; Information derived by server from TCP connection
; not client EHLO.

Opt-info = [Via] [With] [ID] [For]

Via = "VIA" FWS Link CFWS

With = "WITH" FWS Protocol CFWS

ID = "ID" FWS String / msg-id CFWS

For = "FOR" FWS 1*( Path / Mailbox ) CFWS

Link = "TCP" / Addtl-Link
Addtl-Link = Atom
; Additional standard names for links are registered with the
; Internet Assigned Numbers Authority (IANA). "Via" is
; primarily of value with non-Internet transports. SMTP

; servers SHOULD NOT use unregistered names.
Protocol = "ESMTP" / "SMTP" / Attdl-Protocol
Attdl-Protocol = Atom
; Additional standard names for protocols are registered with the
; Internet Assigned Numbers Authority (IANA). SMTP servers
; SHOULD NOT use unregistered names.

4.5 Additional Implementation Issues

4.5.1 Minimum Implementation

In order to make SMTP workable, the following minimum implementation
is required for all receivers. The following commands MUST be
supported to conform to this specification:

EHLO
HELO
MAIL
RCPT
DATA
RSET
NOOP
QUIT
VRFY

Any system that includes an SMTP server supporting mail relaying or
delivery MUST support the reserved mailbox "postmaster" as a case-
insensitive local name. This postmaster address is not strictly
necessary if the server always returns 554 on connection opening (as
described in section 3.1). The requirement to accept mail for
postmaster implies that RCPT commands which specify a mailbox for
postmaster at any of the domains for which the SMTP server provides
mail service, as well as the special case of "RCPT TO:<Postmaster>"
(with no domain specification), MUST be supported.

SMTP systems are expected to make every reasonable effort to accept
mail directed to Postmaster from any other system on the Internet.
In extreme cases --such as to contain a denial of service attack or
other breach of security-- an SMTP server may block mail directed to
Postmaster. However, such arrangements SHOULD be narrowly tailored
so as to avoid blocking messages which are not part of such attacks.

4.5.2 Transparency

Without some provision for data transparency, the character sequence
"<CRLF>.<CRLF>" ends the mail text and cannot be sent by the user.
In general, users are not aware of such "forbidden" sequences. To

allow all user composed text to be transmitted transparently, the
following procedures are used:

- Before sending a line of mail text, the SMTP client checks the
first character of the line. If it is a period, one additional
period is inserted at the beginning of the line.

- When a line of mail text is received by the SMTP server, it checks
the line. If the line is composed of a single period, it is
treated as the end of mail indicator. If the first character is a
period and there are other characters on the line, the first
character is deleted.

The mail data may contain any of the 128 ASCII characters. All
characters are to be delivered to the recipient's mailbox, including
spaces, vertical and horizontal tabs, and other control characters.
If the transmission channel provides an 8-bit byte (octet) data
stream, the 7-bit ASCII codes are transmitted right justified in the
octets, with the high order bits cleared to zero. See 3.7 for
special treatment of these conditions in SMTP systems serving a relay
function.

In some systems it may be necessary to transform the data as it is
received and stored. This may be necessary for hosts that use a
different character set than ASCII as their local character set, that
store data in records rather than strings, or which use special
character sequences as delimiters inside mailboxes. If such
transformations are necessary, they MUST be reversible, especially if
they are applied to mail being relayed.

4.5.3 Sizes and Timeouts

4.5.3.1 Size limits and minimums

There are several objects that have required minimum/maximum sizes.
Every implementation MUST be able to receive objects of at least
these sizes. Objects larger than these sizes SHOULD be avoided when
possible. However, some Internet mail constructs such as encoded
X.400 addresses [16] will often require larger objects: clients MAY
attempt to transmit these, but MUST be prepared for a server to
reject them if they cannot be handled by it. To the maximum extent
possible, implementation techniques which impose no limits on the
length of these objects should be used.

local-part
The maximum total length of a user name or other local-part is 64
characters.

domain
The maximum total length of a domain name or number is 255
characters.

path
The maximum total length of a reverse-path or forward-path is 256
characters (including the punctuation and element separators).

command line
The maximum total length of a command line including the command
word and the <CRLF> is 512 characters. SMTP extensions may be
used to increase this limit.

reply line
The maximum total length of a reply line including the reply code
and the <CRLF> is 512 characters. More information may be
conveyed through multiple-line replies.

text line
The maximum total length of a text line including the <CRLF> is
1000 characters (not counting the leading dot duplicated for
transparency). This number may be increased by the use of SMTP
Service Extensions.

message content
The maximum total length of a message content (including any
message headers as well as the message body) MUST BE at least 64K
octets. Since the introduction of Internet standards for
multimedia mail [12], message lengths on the Internet have grown
dramatically, and message size restrictions should be avoided if
at all possible. SMTP server systems that must impose
restrictions SHOULD implement the "SIZE" service extension [18],
and SMTP client systems that will send large messages SHOULD
utilize it when possible.

recipients buffer
The minimum total number of recipients that must be buffered is
100 recipients. Rejection of messages (for excessive recipients)
with fewer than 100 RCPT commands is a violation of this
specification. The general principle that relaying SMTP servers
MUST NOT, and delivery SMTP servers SHOULD NOT, perform validation
tests on message headers suggests that rejecting a message based
on the total number of recipients shown in header fields is to be
discouraged. A server which imposes a limit on the number of
recipients MUST behave in an orderly fashion, such as to reject
additional addresses over its limit rather than silently
discarding addresses previously accepted. A client that needs to

deliver a message containing over 100 RCPT commands SHOULD be
prepared to transmit in 100-recipient "chunks" if the server
declines to accept more than 100 recipients in a single message.

Errors due to exceeding these limits may be reported by using the
reply codes. Some examples of reply codes are:

500 Line too long.
or
501 Path too long
or
452 Too many recipients (see below)
or
552 Too much mail data.

RFC821 [30] incorrectly listed the error where an SMTP server
exhausts its implementation limit on the number of RCPT commands
("too many recipients") as having reply code 552. The correct reply
code for this condition is 452. Clients SHOULD treat a 552 code in
this case as a temporary, rather than permanent, failure so the logic
below works.

When a conforming SMTP server encounters this condition, it has at
least 100 successful RCPT commands in its recipients buffer. If the
server is able to accept the message, then at least these 100
addresses will be removed from the SMTP client's queue. When the
client attempts retransmission of those addresses which received 452
responses, at least 100 of these will be able to fit in the SMTP
server's recipients buffer. Each retransmission attempt which is
able to deliver anything will be able to dispose of at least 100 of
these recipients.

If an SMTP server has an implementation limit on the number of RCPT
commands and this limit is exhausted, it MUST use a response code of
452 (but the client SHOULD also be prepared for a 552, as noted
above). If the server has a configured site-policy limitation on the
number of RCPT commands, it MAY instead use a 5XX response code.
This would be most appropriate if the policy limitation was intended
to apply if the total recipient count for a particular message body
were enforced even if that message body was sent in multiple mail
transactions.

4.5.3.2 Timeouts

An SMTP client MUST provide a timeout mechanism. It MUST use per-
command timeouts rather than somehow trying to time the entire mail
transaction. Timeouts SHOULD be easily reconfigurable, preferably
without recompiling the SMTP code. To implement this, a timer is set

for each SMTP command and for each buffer of the data transfer. The
latter means that the overall timeout is inherently proportional to
the size of the message.

Based on extensive experience with busy mail-relay hosts, the minimum
per-command timeout values SHOULD be as follows:

Initial 220 Message: 5 minutes
An SMTP client process needs to distinguish between a failed TCP
connection and a delay in receiving the initial 220 greeting
message. Many SMTP servers accept a TCP connection but delay
delivery of the 220 message until their system load permits more
mail to be processed.

MAIL Command: 5 minutes

RCPT Command: 5 minutes
A longer timeout is required if processing of mailing lists and
aliases is not deferred until after the message was accepted.

DATA Initiation: 2 minutes
This is while awaiting the "354 Start Input" reply to a DATA
command.

Data Block: 3 minutes
This is while awaiting the completion of each TCP SEND call
transmitting a chunk of data.

DATA Termination: 10 minutes.
This is while awaiting the "250 OK" reply. When the receiver gets
the final period terminating the message data, it typically
performs processing to deliver the message to a user mailbox. A
spurious timeout at this point would be very wasteful and would
typically result in delivery of multiple copies of the message,
since it has been successfully sent and the server has accepted
responsibility for delivery. See section 6.1 for additional
discussion.

An SMTP server SHOULD have a timeout of at least 5 minutes while it
is awaiting the next command from the sender.

4.5.4 Retry Strategies

The common structure of a host SMTP implementation includes user
mailboxes, one or more areas for queuing messages in transit, and one
or more daemon processes for sending and receiving mail. The exact
structure will vary depending on the needs of the users on the host

and the number and size of mailing lists supported by the host. We
describe several optimizations that have proved helpful, particularly
for mailers supporting high traffic levels.

Any queuing strategy MUST include timeouts on all activities on a
per-command basis. A queuing strategy MUST NOT send error messages
in response to error messages under any circumstances.

4.5.4.1 Sending Strategy

The general model for an SMTP client is one or more processes that
periodically attempt to transmit outgoing mail. In a typical system,
the program that composes a message has some method for requesting
immediate attention for a new piece of outgoing mail, while mail that
cannot be transmitted immediately MUST be queued and periodically
retried by the sender. A mail queue entry will include not only the
message itself but also the envelope information.

The sender MUST delay retrying a particular destination after one
attempt has failed. In general, the retry interval SHOULD be at
least 30 minutes; however, more sophisticated and variable strategies
will be beneficial when the SMTP client can determine the reason for
non-delivery.

Retries continue until the message is transmitted or the sender gives
up; the give-up time generally needs to be at least 4-5 days. The
parameters to the retry algorithm MUST be configurable.

A client SHOULD keep a list of hosts it cannot reach and
corresponding connection timeouts, rather than just retrying queued
mail items.

Experience suggests that failures are typically transient (the target
system or its connection has crashed), favoring a policy of two
connection attempts in the first hour the message is in the queue,
and then backing off to one every two or three hours.

The SMTP client can shorten the queuing delay in cooperation with the
SMTP server. For example, if mail is received from a particular
address, it is likely that mail queued for that host can now be sent.
Application of this principle may, in many cases, eliminate the
requirement for an explicit "send queues now" function such as ETRN
[9].

The strategy may be further modified as a result of multiple
addresses per host (see below) to optimize delivery time vs. resource
usage.

An SMTP client may have a large queue of messages for each
unavailable destination host. If all of these messages were retried
in every retry cycle, there would be excessive Internet overhead and
the sending system would be blocked for a long period. Note that an
SMTP client can generally determine that a delivery attempt has
failed only after a timeout of several minutes and even a one-minute
timeout per connection will result in a very large delay if retries
are repeated for dozens, or even hundreds, of queued messages to the
same host.

At the same time, SMTP clients SHOULD use great care in caching
negative responses from servers. In an extreme case, if EHLO is
issued multiple times during the same SMTP connection, different
answers may be returned by the server. More significantly, 5yz
responses to the MAIL command MUST NOT be cached.

When a mail message is to be delivered to multiple recipients, and
the SMTP server to which a copy of the message is to be sent is the
same for multiple recipients, then only one copy of the message
SHOULD be transmitted. That is, the SMTP client SHOULD use the
command sequence: MAIL, RCPT, RCPT,... RCPT, DATA instead of the
sequence: MAIL, RCPT, DATA, ..., MAIL, RCPT, DATA. However, if there
are very many addresses, a limit on the number of RCPT commands per
MAIL command MAY be imposed. Implementation of this efficiency
feature is strongly encouraged.

Similarly, to achieve timely delivery, the SMTP client MAY support
multiple concurrent outgoing mail transactions. However, some limit
may be appropriate to protect the host from devoting all its
resources to mail.

4.5.4.2 Receiving Strategy

The SMTP server SHOULD attempt to keep a pending listen on the SMTP
port at all times. This requires the support of multiple incoming
TCP connections for SMTP. Some limit MAY be imposed but servers that
cannot handle more than one SMTP transaction at a time are not in
conformance with the intent of this specification.

As discussed above, when the SMTP server receives mail from a
particular host address, it could activate its own SMTP queuing
mechanisms to retry any mail pending for that host address.

4.5.5 Messages with a null reverse-path

There are several types of notification messages which are required
by existing and proposed standards to be sent with a null reverse
path, namely non-delivery notifications as discussed in section 3.7,

other kinds of Delivery Status Notifications (DSNs) [24], and also
Message Disposition Notifications (MDNs) [10]. All of these kinds of
messages are notifications about a previous message, and they are
sent to the reverse-path of the previous mail message. (If the
delivery of such a notification message fails, that usually indicates
a problem with the mail system of the host to which the notification
message is addressed. For this reason, at some hosts the MTA is set
up to forward such failed notification messages to someone who is
able to fix problems with the mail system, e.g., via the postmaster
alias.)

All other types of messages (i.e., any message which is not required
by a standards-track RFCto have a null reverse-path) SHOULD be sent
with with a valid, non-null reverse-path.

Implementors of automated email processors should be careful to make
sure that the various kinds of messages with null reverse-path are
handled correctly, in particular such systems SHOULD NOT reply to
messages with null reverse-path.

5. Address Resolution and Mail Handling

Once an SMTP client lexically identifies a domain to which mail will
be delivered for processing (as described in sections 3.6 and 3.7), a
DNS lookup MUST be performed to resolve the domain name [22]. The
names are expected to be fully-qualified domain names (FQDNs):
mechanisms for inferring FQDNs from partial names or local aliases
are outside of this specification and, due to a history of problems,
are generally discouraged. The lookup first attempts to locate an MX
record associated with the name. If a CNAME record is found instead,
the resulting name is processed as if it were the initial name. If
no MX records are found, but an A RR is found, the A RR is treated as
if it was associated with an implicit MX RR, with a preference of 0,
pointing to that host. If one or more MX RRs are found for a given
name, SMTP systems MUST NOT utilize any A RRs associated with that
name unless they are located using the MX RRs; the "implicit MX" rule
above applies only if there are no MX records present. If MX records
are present, but none of them are usable, this situation MUST be
reported as an error.

When the lookup succeeds, the mapping can result in a list of
alternative delivery addresses rather than a single address, because
of multiple MX records, multihoming, or both. To provide reliable
mail transmission, the SMTP client MUST be able to try (and retry)
each of the relevant addresses in this list in order, until a
delivery attempt succeeds. However, there MAY also be a configurable
limit on the number of alternate addresses that can be tried. In any
case, the SMTP client SHOULD try at least two addresses.

Two types of information is used to rank the host addresses: multiple
MX records, and multihomed hosts.

Multiple MX records contain a preference indication that MUST be used
in sorting (see below). Lower numbers are more preferred than higher
ones. If there are multiple destinations with the same preference
and there is no clear reason to favor one (e.g., by recognition of an
easily-reached address), then the sender-SMTP MUST randomize them to
spread the load across multiple mail exchangers for a specific
organization.

The destination host (perhaps taken from the preferred MX record) may
be multihomed, in which case the domain name resolver will return a
list of alternative IP addresses. It is the responsibility of the
domain name resolver interface to have ordered this list by
decreasing preference if necessary, and SMTP MUST try them in the
order presented.

Although the capability to try multiple alternative addresses is
required, specific installations may want to limit or disable the use
of alternative addresses. The question of whether a sender should
attempt retries using the different addresses of a multihomed host
has been controversial. The main argument for using the multiple
addresses is that it maximizes the probability of timely delivery,
and indeed sometimes the probability of any delivery; the counter-
argument is that it may result in unnecessary resource use. Note
that resource use is also strongly determined by the sending strategy
discussed in section 4.5.4.1.

If an SMTP server receives a message with a destination for which it
is a designated Mail eXchanger, it MAY relay the message (potentially
after having rewritten the MAIL FROM and/or RCPT TO addresses), make
final delivery of the message, or hand it off using some mechanism
outside the SMTP-provided transport environment. Of course, neither
of the latter require that the list of MX records be examined
further.

If it determines that it should relay the message without rewriting
the address, it MUST sort the MX records to determine candidates for
delivery. The records are first ordered by preference, with the
lowest-numbered records being most preferred. The relay host MUST
then inspect the list for any of the names or addresses by which it
might be known in mail transactions. If a matching record is found,
all records at that preference level and higher-numbered ones MUST be
discarded from consideration. If there are no records left at that
point, it is an error condition, and the message MUST be returned as
undeliverable. If records do remain, they SHOULD be tried, best
preference first, as described above.

6. Problem Detection and Handling

6.1 Reliable Delivery and Replies by Email

When the receiver-SMTP accepts a piece of mail (by sending a "250 OK"
message in response to DATA), it is accepting responsibility for
delivering or relaying the message. It must take this responsibility
seriously. It MUST NOT lose the message for frivolous reasons, such
as because the host later crashes or because of a predictable
resource shortage.

If there is a delivery failure after acceptance of a message, the
receiver-SMTP MUST formulate and mail a notification message. This
notification MUST be sent using a null ("<>") reverse path in the
envelope. The recipient of this notification MUST be the address
from the envelope return path (or the Return-Path: line). However,
if this address is null ("<>"), the receiver-SMTP MUST NOT send a
notification. Obviously, nothing in this section can or should
prohibit local decisions (i.e., as part of the same system
environment as the receiver-SMTP) to log or otherwise transmit
information about null address events locally if that is desired. If
the address is an explicit source route, it MUST be stripped down to
its final hop.

For example, suppose that an error notification must be sent for a
message that arrived with:

MAIL FROM:<@a,@b:user@d>

The notification message MUST be sent using:

RCPT TO:<user@d>

Some delivery failures after the message is accepted by SMTP will be
unavoidable. For example, it may be impossible for the receiving
SMTP server to validate all the delivery addresses in RCPT command(s)
due to a "soft" domain system error, because the target is a mailing
list (see earlier discussion of RCPT), or because the server is
acting as a relay and has no immediate access to the delivering
system.

To avoid receiving duplicate messages as the result of timeouts, a
receiver-SMTP MUST seek to minimize the time required to respond to
the final <CRLF>.<CRLF> end of data indicator. See RFC1047 [28] for
a discussion of this problem.

6.2 Loop Detection

Simple counting of the number of "Received:" headers in a message has
proven to be an effective, although rarely optimal, method of
detecting loops in mail systems. SMTP servers using this technique
SHOULD use a large rejection threshold, normally at least 100
Received entries. Whatever mechanisms are used, servers MUST contain
provisions for detecting and stopping trivial loops.

6.3 Compensating for Irregularities

Unfortunately, variations, creative interpretations, and outright
violations of Internet mail protocols do occur; some would suggest
that they occur quite frequently. The debate as to whether a well-
behaved SMTP receiver or relay should reject a malformed message,
attempt to pass it on unchanged, or attempt to repair it to increase
the odds of successful delivery (or subsequent reply) began almost
with the dawn of structured network mail and shows no signs of
abating. Advocates of rejection claim that attempted repairs are
rarely completely adequate and that rejection of bad messages is the
only way to get the offending software repaired. Advocates of
"repair" or "deliver no matter what" argue that users prefer that
mail go through it if at all possible and that there are significant
market pressures in that direction. In practice, these market
pressures may be more important to particular vendors than strict
conformance to the standards, regardless of the preference of the
------分隔线----------------------------
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
最新评论 查看所有评论
发表评论 查看所有评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
推荐内容