Section 4. The SMTP Specifications

4.1.  SMTP Commands
4.1.1.  Command Semantics and Syntax
   The SMTP commands define the mail transfer or the mail system
   function requested by the user.  SMTP commands are character strings
   terminated by <CRLF>.  The commands themselves are alphabetic
   characters terminated by <SP> if parameters follow and <CRLF>
   otherwise.  (In the interest of improved interoperability, SMTP
   receivers SHOULD tolerate trailing white space before the terminating
   <CRLF>.)  The syntax of the local part of a mailbox MUST conform to
   receiver site conventions and the syntax specified in Section 4.1.2.
   The SMTP commands are discussed below.  The SMTP replies are
   discussed in Section 4.2.
   A mail transaction involves several data objects that are
   communicated as arguments to different commands.  The reverse-path is
   the argument of the MAIL command, the forward-path is the argument of
   the RCPT command, and the mail data is the argument of the DATA
   command.  These arguments or data objects must be transmitted and
   held, pending the confirmation communicated by the end of mail data
   indication that finalizes the transaction.  The model for this is
   that distinct buffers are provided to hold the types of data objects;
   that is, there is a reverse-path buffer, a forward-path buffer, and a
   mail data buffer.  Specific commands cause information to be appended
   to a specific buffer, or cause one or more buffers to be cleared.
   Several commands (RSET, DATA, QUIT) are specified as not permitting
   parameters.  In the absence of specific extensions offered by the
   server and accepted by the client, clients MUST NOT send such
   parameters and servers SHOULD reject commands containing them as
   having invalid syntax.
4.1.1.1.  Extended HELLO (EHLO) or HELLO (HELO)
   These commands are used to identify the SMTP client to the SMTP
   server.  The argument clause contains the fully-qualified domain name
   of the SMTP client, if one is available.  In situations in which the
   SMTP client system does not have a meaningful domain name (e.g., when
   its address is dynamically allocated and no reverse mapping record is
   available), the client SHOULD send an address literal (see
   Section 4.1.3).
   RFC 2821, and some earlier informal practices, encouraged following
   the literal by information that would help to identify the client
   system.  That convention was not widely supported, and many SMTP
   servers considered it an error.  In the interest of interoperability,
   it is probably wise for servers to be prepared for this string to
   occur, but SMTP clients SHOULD NOT send it.
   The SMTP server identifies itself to the SMTP client in the
   connection greeting reply and in the response to this command.
   A client SMTP SHOULD start an SMTP session by issuing the EHLO
   command.  If the SMTP server supports the SMTP service extensions, it
   will give a successful response, a failure response, or an error
   response.  If the SMTP server, in violation of this specification,
   does not support any SMTP service extensions, it will generate an
   error response.  Older client SMTP systems MAY, as discussed above,
   use HELO (as specified in RFC 821) instead of EHLO, and servers MUST
   support the HELO command and reply properly to it.  In any event, a
   client MUST issue HELO or EHLO before starting a mail transaction.
   These commands, and a "250 OK" reply to one of them, confirm that
   both the SMTP client and the SMTP server are in the initial state,
   that is, there is no transaction in progress and all state tables and
   buffers are cleared.
   Syntax:
   ehlo           = "EHLO" SP ( Domain / address-literal ) CRLF
   helo           = "HELO" SP Domain CRLF
   Normally, the response to EHLO will be a multiline reply.  Each line
   of the response contains a keyword and, optionally, one or more
   parameters.  Following the normal syntax for multiline replies, these
   keywords follow the code (250) and a hyphen for all but the last
   line, and the code and a space for the last line.  The syntax for a
   positive response, using the ABNF notation and terminal symbols of
   RFC 5234 [7], is:
   ehlo-ok-rsp    = ( "250" SP Domain [ SP ehlo-greet ] CRLF )
                    / ( "250-" Domain [ SP ehlo-greet ] CRLF
                    *( "250-" ehlo-line CRLF )
                    "250" SP ehlo-line CRLF )
   ehlo-greet     = 1*(%d0-9 / %d11-12 / %d14-127)
                    ; string of any characters other than CR or LF
   ehlo-line      = ehlo-keyword *( SP ehlo-param )
   ehlo-keyword   = (ALPHA / DIGIT) *(ALPHA / DIGIT / "-")
                    ; additional syntax of ehlo-params depends on
                    ; ehlo-keyword
   ehlo-param     = 1*(%d33-126)
                    ; any CHAR excluding <SP> and all
                    ; control characters (US-ASCII 0-31 and 127
                    ; inclusive)
   Although EHLO keywords may be specified in upper, lower, or mixed
   case, they MUST always be recognized and processed in a case-
   insensitive manner.  This is simply an extension of practices
   specified in RFC 821 and Section 2.4.
   The EHLO response MUST contain keywords (and associated parameters if
   required) for all commands not listed as "required" in Section 4.5.1
   excepting only private-use commands as described in Section 4.1.5.
   Private-use commands MAY be listed.
4.1.1.2.  MAIL (MAIL)
   This command is used to initiate a mail transaction in which the mail
   data is delivered to an SMTP server that may, in turn, deliver it to
   one or more mailboxes or pass it on to another system (possibly using
   SMTP).  The argument clause contains a reverse-path and may contain
   optional parameters.  In general, the MAIL command may be sent only
   when no mail transaction is in progress, see Section 4.1.4.
   The reverse-path consists of the sender mailbox.  Historically, that
   mailbox might optionally have been preceded by a list of hosts, but
   that behavior is now deprecated (see Appendix C).  In some types of
   reporting messages for which a reply is likely to cause a mail loop
   (for example, mail delivery and non-delivery notifications), the
   reverse-path may be null (see Section 3.6).
   This command clears the reverse-path buffer, the forward-path buffer,
   and the mail data buffer, and it inserts the reverse-path information
   from its argument clause into the reverse-path buffer.
   If service extensions were negotiated, the MAIL command may also
   carry parameters associated with a particular service extension.
   Syntax:
   mail = "MAIL FROM:" Reverse-path
                                       [SP Mail-parameters] CRLF
4.1.1.3.  RECIPIENT (RCPT)
   This command is used to identify an individual recipient of the mail
   data; multiple recipients are specified by multiple uses of this
   command.  The argument clause contains a forward-path and may contain
   optional parameters.
   The forward-path normally consists of the required destination
   mailbox.  Sending systems SHOULD NOT generate the optional list of
   hosts known as a source route.  Receiving systems MUST recognize
   source route syntax but SHOULD strip off the source route
   specification and utilize the domain name associated with the mailbox
   as if the source route had not been provided.
   Similarly, relay hosts SHOULD strip or ignore source routes, and
   names MUST NOT be copied into the reverse-path.  When mail reaches
   its ultimate destination (the forward-path contains only a
   destination mailbox), the SMTP server inserts it into the destination
   mailbox in accordance with its host mail conventions.
   This command appends its forward-path argument to the forward-path
   buffer; it does not change the reverse-path buffer nor the mail data
   buffer.
   For example, mail received at relay host xyz.com with envelope
   commands
      MAIL FROM:<userx@y.foo.org>
      RCPT TO:<@hosta.int,@jkl.org:userc@d.bar.org>
   will normally be sent directly on to host d.bar.org with envelope
   commands
      MAIL FROM:<userx@y.foo.org>
      RCPT TO:<userc@d.bar.org>
   As provided in Appendix C, xyz.com MAY also choose to relay the
   message to hosta.int, using the envelope commands
      MAIL FROM:<userx@y.foo.org>
      RCPT TO:<@hosta.int,@jkl.org:userc@d.bar.org>
   or to jkl.org, using the envelope commands
      MAIL FROM:<userx@y.foo.org>
      RCPT TO:<@jkl.org:userc@d.bar.org>
   Attempting to use relaying this way is now strongly discouraged.
   Since hosts are not required to relay mail at all, xyz.com MAY also
   reject the message entirely when the RCPT command is received, using
   a 550 code (since this is a "policy reason").
   If service extensions were negotiated, the RCPT command may also
   carry parameters associated with a particular service extension
   offered by the server.  The client MUST NOT transmit parameters other
   than those associated with a service extension offered by the server
   in its EHLO response.
   Syntax:
      rcpt = "RCPT TO:" ( "<Postmaster@" Domain ">" / "<Postmaster>" /
                  Forward-path ) [SP Rcpt-parameters] CRLF
                  Note that, in a departure from the usual rules for
                  local-parts, the "Postmaster" string shown above is
                  treated as case-insensitive.
4.1.1.4.  DATA (DATA)
   The receiver normally sends a 354 response to DATA, and then treats
   the lines (strings ending in <CRLF> sequences, as described in
   Section 2.3.7) following the command as mail data from the sender.
   This command causes the mail data to be appended to the mail data
   buffer.  The mail data may contain any of the 128 ASCII character
   codes, although experience has indicated that use of control
   characters other than SP, HT, CR, and LF may cause problems and
   SHOULD be avoided when possible.
   The mail data are terminated by a line containing only a period, that
   is, the character sequence "<CRLF>.<CRLF>", where the first <CRLF> is
   actually the terminator of the previous line (see Section 4.5.2).
   This is the end of mail data indication.  The first <CRLF> of this
   terminating sequence is also the <CRLF> that ends the final line of
   the data (message text) or, if there was no mail data, ends the DATA
   command itself (the "no mail data" case does not conform to this
   specification since it would require that neither the trace header
   fields required by this specification nor the message header section
   required by RFC 5322 [4] be transmitted).  An extra <CRLF> MUST NOT
   be added, as that would cause an empty line to be added to the
   message.  The only exception to this rule would arise if the message
   body were passed to the originating SMTP-sender with a final "line"
   that did not end in <CRLF>; in that case, the originating SMTP system
   MUST either reject the message as invalid or add <CRLF> in order to
   have the receiving SMTP server recognize the "end of data" condition.
   The custom of accepting lines ending only in <LF>, as a concession to
   non-conforming behavior on the part of some UNIX systems, has proven
   to cause more interoperability problems than it solves, and SMTP
   server systems MUST NOT do this, even in the name of improved
   robustness.  In particular, the sequence "<LF>.<LF>" (bare line
   feeds, without carriage returns) MUST NOT be treated as equivalent to
   <CRLF>.<CRLF> as the end of mail data indication.
   Receipt of the end of mail data indication requires the server to
   process the stored mail transaction information.  This processing
   consumes the information in the reverse-path buffer, the forward-path
   buffer, and the mail data buffer, and on the completion of this
   command these buffers are cleared.  If the processing is successful,
   the receiver MUST send an OK reply.  If the processing fails, the
   receiver MUST send a failure reply.  The SMTP model does not allow
   for partial failures at this point: either the message is accepted by
   the server for delivery and a positive response is returned or it is
   not accepted and a failure reply is returned.  In sending a positive
   "250 OK" completion reply to the end of data indication, the receiver
   takes full responsibility for the message (see Section 6.1).  Errors
   that are diagnosed subsequently MUST be reported in a mail message,
   as discussed in Section 4.4.
   When the SMTP server accepts a message either for relaying or for
   final delivery, it inserts a trace record (also referred to
   interchangeably as a "time stamp line" or "Received" line) at the top
   of the mail data.  This trace record indicates the identity of the
   host that sent the message, the identity of the host that received
   the message (and is inserting this time stamp), and the date and time
   the message was received.  Relayed messages will have multiple time
   stamp lines.  Details for formation of these lines, including their
   syntax, is specified in Section 4.4.
   Additional discussion about the operation of the DATA command appears
   in Section 3.3.
   Syntax:
      data = "DATA" CRLF
4.1.1.5.  RESET (RSET)
   This command specifies that the current mail transaction will be
   aborted.  Any stored sender, recipients, and mail data MUST be
   discarded, and all buffers and state tables cleared.  The receiver
   MUST send a "250 OK" reply to a RSET command with no arguments.  A
   reset command may be issued by the client at any time.  It is
   effectively equivalent to a NOOP (i.e., it has no effect) if issued
   immediately after EHLO, before EHLO is issued in the session, after
   an end of data indicator has been sent and acknowledged, or
   immediately before a QUIT.  An SMTP server MUST NOT close the
   connection as the result of receiving a RSET; that action is reserved
   for QUIT (see Section 4.1.1.10).
   Since EHLO implies some additional processing and response by the
   server, RSET will normally be more efficient than reissuing that
   command, even though the formal semantics are the same.
   There are circumstances, contrary to the intent of this
   specification, in which an SMTP server may receive an indication that
   the underlying TCP connection has been closed or reset.  To preserve
   the robustness of the mail system, SMTP servers SHOULD be prepared
   for this condition and SHOULD treat it as if a QUIT had been received
   before the connection disappeared.
   Syntax:
      rset = "RSET" CRLF
4.1.1.6.  VERIFY (VRFY)
   This command asks the receiver to confirm that the argument
   identifies a user or mailbox.  If it is a user name, information is
   returned as specified in Section 3.5.
   This command has no effect on the reverse-path buffer, the forward-
   path buffer, or the mail data buffer.
   Syntax:
      vrfy = "VRFY" SP String CRLF
4.1.1.7.  EXPAND (EXPN)
   This command asks the receiver to confirm that the argument
   identifies a mailing list, and if so, to return the membership of
   that list.  If the command is successful, a reply is returned
   containing information as described in Section 3.5.  This reply will
   have multiple lines except in the trivial case of a one-member list.
   This command has no effect on the reverse-path buffer, the forward-
   path buffer, or the mail data buffer, and it may be issued at any
   time.
   Syntax:
      expn = "EXPN" SP String CRLF
4.1.1.8.  HELP (HELP)
   This command causes the server to send helpful information to the
   client.  The command MAY take an argument (e.g., any command name)
   and return more specific information as a response.
   This command has no effect on the reverse-path buffer, the forward-
   path buffer, or the mail data buffer, and it may be issued at any
   time.
   SMTP servers SHOULD support HELP without arguments and MAY support it
   with arguments.
   Syntax:
      help = "HELP" [ SP String ] CRLF
4.1.1.9.  NOOP (NOOP)
   This command does not affect any parameters or previously entered
   commands.  It specifies no action other than that the receiver send a
   "250 OK" reply.
   This command has no effect on the reverse-path buffer, the forward-
   path buffer, or the mail data buffer, and it may be issued at any
   time.  If a parameter string is specified, servers SHOULD ignore it.
   Syntax:
      noop = "NOOP" [ SP String ] CRLF
4.1.1.10.  QUIT (QUIT)
   This command specifies that the receiver MUST send a "221 OK" reply,
   and then close the transmission channel.
   The receiver MUST NOT intentionally close the transmission channel
   until it receives and replies to a QUIT command (even if there was an
   error).  The sender MUST NOT intentionally close the transmission
   channel until it sends a QUIT command, and it SHOULD wait until it
   receives the reply (even if there was an error response to a previous
   command).  If the connection is closed prematurely due to violations
   of the above or system or network failure, the server MUST cancel any
   pending transaction, but not undo any previously completed
   transaction, and generally MUST act as if the command or transaction
   in progress had received a temporary error (i.e., a 4yz response).
   The QUIT command may be issued at any time.  Any current uncompleted
   mail transaction will be aborted.
   Syntax:
      quit = "QUIT" CRLF
4.1.1.11.  Mail-Parameter and Rcpt-Parameter Error Responses
   If the server SMTP does not recognize or cannot implement one or more
   of the parameters associated with a particular MAIL FROM or RCPT TO
   command, it will return code 555.
   If, for some reason, the server is temporarily unable to accommodate
   one or more of the parameters associated with a MAIL FROM or RCPT TO
   command, and if the definition of the specific parameter does not
   mandate the use of another code, it should return code 455.
   Errors specific to particular parameters and their values will be
   specified in the parameter's defining RFC.
4.1.2.  Command Argument Syntax
   The syntax of the argument clauses of the above commands (using the
   syntax specified in RFC 5234 [7] where applicable) is given below.
   Some of the productions given below are used only in conjunction with
   source routes as described in Appendix C.  Terminals not defined in
   this document, such as ALPHA, DIGIT, SP, CR, LF, CRLF, are as defined
   in the "core" syntax in Section 6 of RFC 5234 [7] or in the message
   format syntax in RFC 5322 [4].
   Reverse-path   = Path / "<>"
   Forward-path   = Path
   Path           = "<" [ A-d-l ":" ] Mailbox ">"
   A-d-l          = At-domain *( "," At-domain )
                  ; Note that this form, the so-called "source
                  ; route", MUST BE accepted, SHOULD NOT be
                  ; generated, and SHOULD be ignored.
   At-domain      = "@" Domain
   Mail-parameters  = esmtp-param *(SP esmtp-param)
   Rcpt-parameters  = esmtp-param *(SP esmtp-param)
   esmtp-param    = esmtp-keyword ["=" esmtp-value]
   esmtp-keyword  = (ALPHA / DIGIT) *(ALPHA / DIGIT / "-")
   esmtp-value    = 1*(%d33-60 / %d62-126)
                  ; any CHAR excluding "=", SP, and control
                  ; characters.  If this string is an email address,
                  ; i.e., a Mailbox, then the "xtext" syntax [32]
                  ; SHOULD be used.
   Keyword        = Ldh-str
   Argument       = Atom
   Domain         = sub-domain *("." sub-domain)
   sub-domain     = Let-dig [Ldh-str]
   Let-dig        = ALPHA / DIGIT
   Ldh-str        = *( ALPHA / DIGIT / "-" ) Let-dig
   address-literal  = "[" ( IPv4-address-literal /
                    IPv6-address-literal /
                    General-address-literal ) "]"
                    ; See Section 4.1.3
   Mailbox        = Local-part "@" ( Domain / address-literal )
   Local-part     = Dot-string / Quoted-string
                  ; MAY be case-sensitive
   Dot-string     = Atom *("."  Atom)
   Atom           = 1*atext
   Quoted-string  = DQUOTE *QcontentSMTP DQUOTE
   QcontentSMTP   = qtextSMTP / quoted-pairSMTP
   quoted-pairSMTP  = %d92 %d32-126
                    ; i.e., backslash followed by any ASCII
                    ; graphic (including itself) or SPace
   qtextSMTP      = %d32-33 / %d35-91 / %d93-126
                  ; i.e., within a quoted string, any
                  ; ASCII graphic or space is permitted
                  ; without blackslash-quoting except
                  ; double-quote and the backslash itself.
   String         = Atom / Quoted-string
   While the above definition for Local-part is relatively permissive,
   for maximum interoperability, a host that expects to receive mail
   SHOULD avoid defining mailboxes where the Local-part requires (or
   uses) the Quoted-string form or where the Local-part is case-
   sensitive.  For any purposes that require generating or comparing
   Local-parts (e.g., to specific mailbox names), all quoted forms MUST
   be treated as equivalent, and the sending system SHOULD transmit the
   form that uses the minimum quoting possible.
   Systems MUST NOT define mailboxes in such a way as to require the use
   in SMTP of non-ASCII characters (octets with the high order bit set
   to one) or ASCII "control characters" (decimal value 0-31 and 127).
   These characters MUST NOT be used in MAIL or RCPT commands or other
   commands that require mailbox names.
   Note that the backslash, "\", is a quote character, which is used to
   indicate that the next character is to be used literally (instead of
   its normal interpretation).  For example, "Joe\,Smith" indicates a
   single nine-character user name string with the comma being the
   fourth character of that string.
   To promote interoperability and consistent with long-standing
   guidance about conservative use of the DNS in naming and applications
   (e.g., see Section 2.3.1 of the base DNS document, RFC 1035 [2]),
   characters outside the set of alphabetic characters, digits, and
   hyphen MUST NOT appear in domain name labels for SMTP clients or
   servers.  In particular, the underscore character is not permitted.
   SMTP servers that receive a command in which invalid character codes
   have been employed, and for which there are no other reasons for
   rejection, MUST reject that command with a 501 response (this rule,
   like others, could be overridden by appropriate SMTP extensions).
4.1.3.  Address Literals
   Sometimes a host is not known to the domain name system and
   communication (and, in particular, communication to report and repair
   the error) is blocked.  To bypass this barrier, a special literal
   form of the address is allowed as an alternative to a domain name.
   For IPv4 addresses, this form uses four small decimal integers
   separated by dots and enclosed by brackets such as [123.255.37.2],
   which indicates an (IPv4) Internet Address in sequence-of-octets
   form.  For IPv6 and other forms of addressing that might eventually
   be standardized, the form consists of a standardized "tag" that
   identifies the address syntax, a colon, and the address itself, in a
   format specified as part of the relevant standards (i.e., RFC 4291
   [8] for IPv6).
   Specifically:
   IPv4-address-literal  = Snum 3("."  Snum)
   IPv6-address-literal  = "IPv6:" IPv6-addr
   General-address-literal  = Standardized-tag ":" 1*dcontent
   Standardized-tag  = Ldh-str
                     ; Standardized-tag MUST be specified in a
                     ; Standards-Track RFC and registered with IANA
   dcontent       = %d33-90 / ; Printable US-ASCII
                  %d94-126 ; excl. "[", "\", "]"
   Snum           = 1*3DIGIT
                  ; representing a decimal integer
                  ; value in the range 0 through 255
   IPv6-addr      = IPv6-full / IPv6-comp / IPv6v4-full / IPv6v4-comp
   IPv6-hex       = 1*4HEXDIG
   IPv6-full      = IPv6-hex 7(":" IPv6-hex)
   IPv6-comp      = [IPv6-hex *5(":" IPv6-hex)] "::"
                  [IPv6-hex *5(":" IPv6-hex)]
                  ; The "::" represents at least 2 16-bit groups of
                  ; zeros.  No more than 6 groups in addition to the
                  ; "::" may be present.
   IPv6v4-full    = IPv6-hex 5(":" IPv6-hex) ":" IPv4-address-literal
   IPv6v4-comp    = [IPv6-hex *3(":" IPv6-hex)] "::"
                  [IPv6-hex *3(":" IPv6-hex) ":"]
                  IPv4-address-literal
                  ; The "::" represents at least 2 16-bit groups of
                  ; zeros.  No more than 4 groups in addition to the
                  ; "::" and IPv4-address-literal may be present.
4.1.4.  Order of Commands
   There are restrictions on the order in which these commands may be
   used.
   A session that will contain mail transactions MUST first be
   initialized by the use of the EHLO command.  An SMTP server SHOULD
   accept commands for non-mail transactions (e.g., VRFY or EXPN)
   without this initialization.
   An EHLO command MAY be issued by a client later in the session.  If
   it is issued after the session begins and the EHLO command is
   acceptable to the SMTP server, the SMTP server MUST clear all buffers
   and reset the state exactly as if a RSET command had been issued.  In
   other words, the sequence of RSET followed immediately by EHLO is
   redundant, but not harmful other than in the performance cost of
   executing unnecessary commands.
   If the EHLO command is not acceptable to the SMTP server, 501, 500,
   502, or 550 failure replies MUST be returned as appropriate.  The
   SMTP server MUST stay in the same state after transmitting these
   replies that it was in before the EHLO was received.
   The SMTP client MUST, if possible, ensure that the domain parameter
   to the EHLO command is a primary host name as specified for this
   command in Section 2.3.5.  If this is not possible (e.g., when the
   client's address is dynamically assigned and the client does not have
   an obvious name), an address literal SHOULD be substituted for the
   domain name.
   An SMTP server MAY verify that the domain name argument in the EHLO
   command actually corresponds to the IP address of the client.
   However, if the verification fails, the server MUST NOT refuse to
   accept a message on that basis.  Information captured in the
   verification attempt is for logging and tracing purposes.  Note that
   this prohibition applies to the matching of the parameter to its IP
   address only; see Section 7.9 for a more extensive discussion of
   rejecting incoming connections or mail messages.
   The NOOP, HELP, EXPN, VRFY, and RSET commands can be used at any time
   during a session, or without previously initializing a session.  SMTP
   servers SHOULD process these normally (that is, not return a 503
   code) even if no EHLO command has yet been received; clients SHOULD
   open a session with EHLO before sending these commands.
   If these rules are followed, the example in RFC 821 that shows "550
   access denied to you" in response to an EXPN command is incorrect
   unless an EHLO command precedes the EXPN or the denial of access is
   based on the client's IP address or other authentication or
   authorization-determining mechanisms.
   The MAIL command (or the obsolete SEND, SOML, or SAML commands)
   begins a mail transaction.  Once started, a mail transaction consists
   of a transaction beginning command, one or more RCPT commands, and a
   DATA command, in that order.  A mail transaction may be aborted by
   the RSET, a new EHLO, or the QUIT command.  There may be zero or more
   transactions in a session.  MAIL (or SEND, SOML, or SAML) MUST NOT be
   sent if a mail transaction is already open, i.e., it should be sent
   only if no mail transaction had been started in the session, or if
   the previous one successfully concluded with a successful DATA
   command, or if the previous one was aborted, e.g., with a RSET or new
   EHLO.
   If the transaction beginning command argument is not acceptable, a
   501 failure reply MUST be returned and the SMTP server MUST stay in
   the same state.  If the commands in a transaction are out of order to
   the degree that they cannot be processed by the server, a 503 failure
   reply MUST be returned and the SMTP server MUST stay in the same
   state.
   The last command in a session MUST be the QUIT command.  The QUIT
   command SHOULD be used by the client SMTP to request connection
   closure, even when no session opening command was sent and accepted.
4.1.5.  Private-Use Commands
   As specified in Section 2.2.2, commands starting in "X" may be used
   by bilateral agreement between the client (sending) and server
   (receiving) SMTP agents.  An SMTP server that does not recognize such
   a command is expected to reply with "500 Command not recognized".  An
   extended SMTP server MAY list the feature names associated with these
   private commands in the response to the EHLO command.
   Commands sent or accepted by SMTP systems that do not start with "X"
   MUST conform to the requirements of Section 2.2.2.
4.2.  SMTP Replies
   Replies to SMTP commands serve to ensure the synchronization of
   requests and actions in the process of mail transfer and to guarantee
   that the SMTP client always knows the state of the SMTP server.
   Every command MUST generate exactly one reply.
   The details of the command-reply sequence are described in
   Section 4.3.
   An SMTP reply consists of a three digit number (transmitted as three
   numeric characters) followed by some text unless specified otherwise
   in this document.  The number is for use by automata to determine
   what state to enter next; the text is for the human user.  The three
   digits contain enough encoded information that the SMTP client need
   not examine the text and may either discard it or pass it on to the
   user, as appropriate.  Exceptions are as noted elsewhere in this
   document.  In particular, the 220, 221, 251, 421, and 551 reply codes
   are associated with message text that must be parsed and interpreted
   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 the same section).  Since, in violation of this
   specification, the text is sometimes not sent, clients that 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 / address-literal)
                  [ SP textstring ] CRLF ) /
                  ( "220-" (Domain / address-literal)
                  [ SP textstring ] CRLF
                  *( "220-" [ textstring ] CRLF )
                  "220" [ SP textstring ] CRLF )
   textstring     = 1*(%d09 / %d32-126) ; HT, SP, Printable US-ASCII
   Reply-line     = *( Reply-code "-" [ textstring ] CRLF )
                  Reply-code [ SP textstring ] CRLF
   Reply-code     = %x32-35 %x30-35 %x30-39
   where "Greeting" appears only in the 220 response that announces that
   the server is opening its part of the connection.  (Other possible
   server responses upon connection follow the syntax of Reply-line.)
   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.
   In the absence of extensions negotiated with the client, SMTP servers
   MUST NOT send reply codes whose first digits are other than 2, 3, 4,
   or 5.  Clients that receive such out-of-range codes SHOULD normally
   treat them as fatal errors and terminate the mail transaction.
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 four values for the first digit of the reply code:
   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 SHOULD 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 SHOULD NOT repeat 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).
   It is worth noting that the file transfer protocol (FTP) [34] uses a
   very similar code architecture and that the SMTP codes are based on
   the FTP model.  However, SMTP uses a one-command, one-response model
   (while FTP is asynchronous) and FTP's 1yz codes are not part of the
   SMTP model.
   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:
      250-First line
      250-Second line
      250-234 Text beginning with numbers
      250 The last line
   In a multiline reply, the reply code on each of the lines MUST be the
   same.  It is reasonable for the client to rely on this, so it can
   make processing decisions based on the code in any line, assuming
   that all others will be the same.  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)
   455  Server unable to accommodate parameters
   555  MAIL FROM/RCPT TO parameters not recognized or not implemented
   450  Requested mail action not taken: mailbox unavailable (e.g.,
      mailbox busy or temporarily blocked for policy reasons)
   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 or temporarily blocked for policy reasons)
   451  Requested action aborted: local error in processing
   452  Requested action not taken: insufficient system storage
   455  Server unable to accommodate parameters
   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")
   555  MAIL FROM/RCPT TO parameters not recognized or not implemented
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:
   o  delivering the message (if the recipient mailbox exists), or
   o  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.
   o  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 temporary error status (4yz) code after
   the DATA command is completed with <CRLF>.<CRLF>, it MUST NOT make a
   subsequent attempt to deliver that message.  The SMTP client retains
   responsibility for the 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.  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 completed 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 of the message and response and appropriate
   intervention.
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 Section 4.1.3 for a discussion of alternatives
   in these situations.
   For example,
      220 ISIF.USC.EDU Service ready
   or
      220 mail.example.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 meanings and actions implied
   by the code numbers and by the specific command reply sequence MUST
   be preserved.
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.  However, if the target is more
   precise granularity in the codes, rather than codes for completely
   new purposes, the system described in RFC 3463 [25] SHOULD be used in
   preference to the invention of new codes.
   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.  Similarly, producing a "command
      too long" message for a command line shorter than 512 characters
      would violate the provisions of Section 4.5.3.1.4.
   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 (a conforming implementation could return this code only
         in fairly obscure cases), 550, 502 (permitted only with an old-
         style server that does not support EHLO)
      MAIL
         S: 250
         E: 552, 451, 452, 550, 553, 503, 455, 555
      RCPT
         S: 250, 251 (but see Section 3.4 for discussion of 251 and 551)
         E: 550, 551, 552, 553, 450, 451, 452, 503, 455, 555
      DATA
         I: 354 -> data -> S: 250
                           E: 552, 554, 451, 452
                           E: 450, 550 (rejections for policy reasons)
         E: 503, 554
      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:
   o  The FROM clause, 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.
   o  The ID clause MAY contain an "@" as suggested in RFC 822, but this
      is not required.
   o  If the FOR clause appears, it MUST contain exactly one <path>
      entry, even when multiple RCPT commands have been given.  Multiple
      <path>s raise some security issues and have been deprecated, see
      Section 7.2.
   An Internet mail program MUST NOT change or delete a Received: line
   that was previously added to the message header section.  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 header fields is
   important for detecting problems, especially slow relays.  SMTP
   servers that create Received header fields SHOULD use explicit
   offsets in the dates (e.g., -0800), rather than time zone names of
   any type.  Local time (with an offset) SHOULD be used rather than 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 rest of the mail data: first the
   balance of the mail header section and then the body (RFC 5322 [4]).
   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 field.  SMTP servers performing
   a relay function MUST NOT inspect the message data, and especially
   not to the extent needed to determine if Return-path header fields
   are present.  SMTP servers making final delivery MAY remove Return-
   path header fields 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 RFC 822 that appears to contradict the use
   of the Return-path header field (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:
   o  a gateway from SMTP -> elsewhere SHOULD insert a return-path
      header field, unless it is known that the "elsewhere" transport
      also uses Internet domain addresses and maintains the envelope
      sender address separately.
   o  a gateway from elsewhere -> SMTP SHOULD delete any return-path
      header field 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
   SHOULD be used when possible.  Note that the key difference between
   handling aliases (Section 3.9.1) and forwarding (this subsection) is
   the change to the backward-pointing address in this case.  All
   notification messages about undeliverable mail MUST be sent using the
   MAIL command (even if they result from processing the obsolete SEND,
   SOML, or SAML commands) and MUST use a null return path as discussed
   in Section 3.6.
   The time stamp line and the return path line are formally defined as
   follows (the definitions for "FWS" and "CFWS" appear in RFC 5322
   [4]):
   Return-path-line  = "Return-Path:" FWS Reverse-path <CRLF>
   Time-stamp-line  = "Received:" FWS Stamp <CRLF>
   Stamp          = From-domain By-domain Opt-info [CFWS] ";"
                  FWS date-time
                  ; where "date-time" is as defined in RFC 5322 [4]
                  ; but the "obs-" forms, especially two-digit
                  ; years, are prohibited in SMTP and MUST NOT be used.
   From-domain    = "FROM" FWS Extended-Domain
   By-domain      = CFWS "BY" FWS Extended-Domain
   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]
                  [Additional-Registered-Clauses]
   Via            = CFWS "VIA" FWS Link
   With           = CFWS "WITH" FWS Protocol
   ID             = CFWS "ID" FWS ( Atom / msg-id )
                  ; msg-id is defined in RFC 5322 [4]
   For            = CFWS "FOR" FWS ( Path / Mailbox )
   Additional-Registered-Clauses  = CFWS Atom FWS String
                                  ; Additional standard clauses may be
                                  added in this
                                  ; location by future standards and
                                  registration with
                                  ; IANA.  SMTP servers SHOULD NOT use
                                  unregistered
                                  ; names.  See Section 8.
   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) in the "mail parameters"
                  ; registry [9].  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
   MUST be provided by 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 that 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 that 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:
   o  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.
   o  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
   Section 3.6 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 (RFC 2156 [35]) 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 that impose no
   limits on the length of these objects should be used.
   Extensions to SMTP may involve the use of characters that occupy more
   than a single octet each.  This section therefore specifies lengths
   in octets where absolute lengths, rather than character counts, are
   intended.
4.5.3.1.1.  Local-part
   The maximum total length of a user name or other local-part is 64
   octets.
4.5.3.1.2.  Domain
   The maximum total length of a domain name or number is 255 octets.
4.5.3.1.3.  Path
   The maximum total length of a reverse-path or forward-path is 256
   octets (including the punctuation and element separators).
4.5.3.1.4.  Command Line
   The maximum total length of a command line including the command word
   and the <CRLF> is 512 octets.  SMTP extensions may be used to
   increase this limit.
4.5.3.1.5.  Reply Line
   The maximum total length of a reply line including the reply code and
   the <CRLF> is 512 octets.  More information may be conveyed through
   multiple-line replies.
4.5.3.1.6.  Text Line
   The maximum total length of a text line including the <CRLF> is 1000
   octets (not counting the leading dot duplicated for transparency).
   This number may be increased by the use of SMTP Service Extensions.
4.5.3.1.7.  Message Content
   The maximum total length of a message content (including any message
   header section as well as the message body) MUST BE at least 64K
   octets.  Since the introduction of Internet Standards for multimedia
   mail (RFC 2045 [21]), 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 of RFC 1870 [10], and
   SMTP client systems that will send large messages SHOULD utilize it
   when possible.
4.5.3.1.8.  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 server MUST NOT, and
   delivery SMTP servers SHOULD NOT, perform validation tests on message
   header fields suggests that messages SHOULD NOT be rejected based on
   the total number of recipients shown in header fields.  A server that
   imposes a limit on the number of recipients MUST behave in an orderly
   fashion, such as rejecting 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.
4.5.3.1.9.  Treatment When Limits Exceeded
   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.
4.5.3.1.10.  Too Many Recipients Code
   RFC 821 [1] 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 that received 452
   responses, at least 100 of these will be able to fit in the SMTP
   server's recipients buffer.  Each retransmission attempt that 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 5yz response code.  In
   particular, if the intent is to prohibit messages with more than a
   site-specified number of recipients, rather than merely limit the
   number of recipients in a given mail transaction, it would be
   reasonable to return a 503 response to any DATA command received
   subsequent to the 452 (or 552) code or to simply return the 503 after
   DATA without returning any previous negative response.
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:
4.5.3.2.1.  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.
4.5.3.2.2.  MAIL Command: 5 Minutes
4.5.3.2.3.  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.
4.5.3.2.4.  DATA Initiation: 2 Minutes
   This is while awaiting the "354 Start Input" reply to a DATA command.
4.5.3.2.5.  Data Block: 3 Minutes
   This is while awaiting the completion of each TCP SEND call
   transmitting a chunk of data.
4.5.3.2.6.  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.
4.5.3.2.7.  Server Timeout: 5 Minutes.
   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.  It MAY
   be appropriate to set a shorter maximum number of retries for non-
   delivery notifications and equivalent error messages than for
   standard messages.  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,
   RFC 1985 [36].
   The strategy may be further modified as a result of multiple
   addresses per host (see below) to optimize delivery time versus
   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.  This efficiency feature SHOULD be
   implemented.
   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 (specified by IANA as port 25) 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 that 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, RFC 3461 [32]), and
   Message Disposition Notifications (MDNs, RFC 3798 [37]).  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 RFC to have a null reverse-path) SHOULD be sent
   with a valid, non-null reverse-path.
   Implementers of automated email processors should be careful to make
   sure that the various kinds of messages with a null reverse-path are
   handled correctly.  In particular, such systems SHOULD NOT reply to
   messages with a null reverse-path, and they SHOULD NOT add a non-null
   reverse-path, or change a null reverse-path to a non-null one, to
   such messages when forwarding.