使用 Telnet 连接 GreenMail 模拟邮件服务器 (测试 SMTP / IMAP 连接)
要求
GreenMail Standalone
本地 Apache 服务器
下载
从 GreenMail 官网直接下载
使用命令行指令下载:
1 | cd /home/user/ |
下载完成以后从终端运行.jar
文件:
1 | java -Dgreenmail.smtp.timeout=120000 -Dgreenmail.smtp.hostname=0.0.0.0 -Dgreenmail.smtp.port=3025 -Dgreenmail.imap.hostname=0.0.0.0 -Dgreenmail.imap.port=3143 -jar /path/to/file/greenmail-standalone-2.1.0-alpha-1.jar |
-Dgreenmail.smtp.timeout
:为防止 SMTP 服务器超时,把超时时常设置为 120000 毫秒
-Dgreenmail.smtp.hostname
,Dgreenmail.smtp.port
:设置 SMTP 地址和端口
-Dgreenmail.imap.hostname
,-Dgreenmail.imap.port
:设置 IMAP 地址和端口
连接 SMTP 服务器
开启 Telnet 进程,连接到 SMTP 服务器的 3025 端口:
1 | telent localhost 3025 |
$ telnet localhost 3025
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 /0:0:0:0:0:0:0:1 GreenMail SMTP Service v2.1.0-alpha-1 ready
421 Service shutting down and closing transmission channel (socket timeout, SO_TIMEOUT: 30000ms)
握手成功了!接下里可以输入四字指令和 SMTP 服务器交流:
C: HELO localhost
S: 250-/0:0:0:0:0:0:0:1
250 AUTH PLAIN LOGIN
C: MAIL FROM: <example@email.com>
S: 250 OK
C: RCPT TO: <example@email.com>
S: 250 OK
C: DATA
S: 354 Start mail input; end with <CRLF>.<CRLF>
C: HELLO THERE
THIS IS USER SPEAKING
.
S: 250 OK
C: QUIT
S: 221 /0:0:0:0:0:0:0:1 Service closing transmission channel
Connection closed by foreign host.
解释一下这些缩写是什么意思:
HELO
: hello
RCPT
: recipient
CRLF
: carriage return & line feed
连接 IMAP 服务器
认证阶段
2023-10-09 14:59:25,387 INFO
user.UserManager| Created user login example@email.com for address example@email.com with password
example@email.com because it didn't exist before.
$ telnet localhost 3110
+OK POP3 server ready
user example@email.com
+OK
pass example@email.com
+OK user successfully logged on
交易阶段
C: list
S: 1 498
S: 2 912
S: .
C: retr 1
S: (blah blah ...
S: .................
S: ..........blah)
S: .
C: dele 1
C: retr 2
S: (blah blah ...
S: .................
S: ..........blah)
S: .
C: dele 2
C: quit
S: +OK POP3 server signing off
用户在这个阶段可以给邮件添加标记,被添加删除标记的邮件将在最后的更新阶段被删除。