跳到主要内容

4.2. SMTP 应答

设计 SMTP 命令的应答,是为了确保邮件传输过程中请求与动作的同步,并保证发送方 SMTP 始终知道接收方 SMTP 的状态。每条命令必须恰好产生一个应答。

命令与应答序列的细节在第 5.3 节"时序"和第 5.4 节"状态图"中有明确说明。

SMTP 应答由一个三位数字(以三个字母数字字符传输)后跟一些文本组成。数字供自动机用来确定下一步进入什么状态,文本则是给人类用户看的。其意图是让这三位数字包含足够的编码信息,使发送方 SMTP 无需检查文本,可以视情况丢弃它或将其转给用户。特别是,文本可能因接收方而异、因上下文而异,因此每个应答码很可能对应各种不同的文本。应答码的理论在附录 E 中讨论。从形式上讲,应答被定义为如下序列:一个三位数字代码、<SP>、一行文本和 <CRLF>,或者是一条多行应答(如附录 E 所定义)。正常情况下只有 EXPN 和 HELP 命令预期会产生多行应答,但任何命令都允许使用多行应答。

4.2.1. 按功能分组的应答码​

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
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>
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]
451 Requested action aborted: error in processing
551 User not local; please try <forward-path>
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

4.2.2. 按数字顺序排列的应答码列表​

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>

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
503 Bad sequence of commands
504 Command parameter not implemented
550 Requested action not taken: mailbox unavailable
[E.g., mailbox not found, no access]
551 User not local; please try <forward-path>
552 Requested mail action aborted: exceeded storage allocation
553 Requested action not taken: mailbox name not allowed
[E.g., mailbox syntax incorrect]
554 Transaction failed