跳到主要内容

附录 D. 场景 (Scenarios)

本附录给出典型 SMTP 事务场景, 用于说明协议操作.

D.1. 典型 SMTP 事务场景

场景: [email protected][email protected] 发送邮件

# Connection establishment
C: <establishes TCP connection to server.example port 25>
S: 220 server.example ESMTP Postfix

# Client greeting
C: EHLO client.example
S: 250-server.example
S: 250-SIZE 52428800
S: 250-8BITMIME
S: 250-STARTTLS
S: 250 HELP

# Mail transaction
C: MAIL FROM:<[email protected]>
S: 250 2.1.0 Ok

C: RCPT TO:<[email protected]>
S: 250 2.1.5 Ok

# Message content
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>

C: From: Alice <[email protected]>
C: To: Bob <[email protected]>
C: Subject: Hello
C: Date: Wed, 24 Dec 2024 10:00:00 +0000
C:
C: Hi Bob,
C:
C: This is a test message.
C:
C: Best regards,
C: Alice
C: .

S: 250 2.0.0 Ok: queued as A1B2C3D4E5

# Session termination
C: QUIT
S: 221 2.0.0 Bye

D.2. 中止的 SMTP 事务场景

场景: 发送者在中途终止事务

S: 220 server.example ESMTP

C: EHLO client.example
S: 250 server.example

C: MAIL FROM:<[email protected]>
S: 250 Ok

C: RCPT TO:<[email protected]>
S: 250 Ok

C: RCPT TO:<[email protected]>
S: 550 5.1.1 User unknown

# Sender decides to abort and start over
C: RSET
S: 250 Ok

# Start new transaction
C: MAIL FROM:<[email protected]>
S: 250 Ok

C: RCPT TO:<[email protected]>
S: 250 Ok

C: DATA
S: 354 Start mail input

C: (message content)
C: .
S: 250 Ok: queued as XYZ123

C: QUIT
S: 221 Bye

D.3. 中继邮件场景

场景: 从 [email protected][email protected] 的邮件经由 relay.example

步骤 1: origin.example -> relay.example

C: EHLO origin.example
S: 250 relay.example

C: MAIL FROM:<[email protected]>
S: 250 Ok

C: RCPT TO:<[email protected]>
S: 250 Ok (relay accepts to forward)

C: DATA
S: 354 Start mail input
C: (message)
C: .
S: 250 Ok: queued for relay

步骤 2: relay.example -> final.example

# relay.example now acts as client
C: EHLO relay.example
S: 250 final.example

C: MAIL FROM:<[email protected]>
S: 250 Ok

C: RCPT TO:<[email protected]>
S: 250 Ok

C: DATA
S: 354 Start mail input
C: Received: from origin.example by relay.example; ...
C: (original message)
C: .
S: 250 Ok: delivered to bob

C: QUIT
S: 221 Bye

D.4. 验证并发送场景

场景: 客户端发送前验证地址

S: 220 server.example ESMTP

C: EHLO client.example
S: 250 server.example

# Verify recipient exists
C: VRFY bob
S: 250 Bob Smith <[email protected]>

# Now send mail
C: MAIL FROM:<[email protected]>
S: 250 Ok

C: RCPT TO:<[email protected]>
S: 250 Ok

C: DATA
S: 354 Start mail input
C: (message)
C: .
S: 250 Ok

C: QUIT
S: 221 Bye

替代情况: 出于安全原因禁用 VRFY

C: VRFY bob
S: 252 2.5.2 Cannot VRFY user, but will accept message

# Client proceeds anyway
C: MAIL FROM:<[email protected]>
S: 250 Ok
...