POP3 Protocol:
POP3,即Post Office Protocol 3,3是它的版本,是目前使用的主流版本。到这篇文章出搞的时候,我参考的是RFC 1939 [Myers&Rose 1998],RFC 1734、RFC2195介绍了鉴权的内容,RFC 2449介绍了扩展内容。
当你需要连接用“]”表示终一个POP3服务器,你可以使用如下的命令行。本文使端显示,
1<host>表示目标主机,可以是IP地址或者是有效的主机名。下面如没有特殊说明,都可认为如此表示:
2] telnet <host> 110
3如果系统使用知名端口列表映射,则可以使用下面的命令行:
4] telnet <host> pop3
5
6我们连接SMTP服务器:
7] telnet pop3.163.com 110
8如果连接成功,服务器会返回如下信息:
9] +OK Welcome to coremail Mail Pop3 Server(163com[20030606])
10可以看到返回了+OK的字样,表示成功地连接到了POP3服务器,POP3服务器使用+OK的返回表示命令成功执行,而用-ERR的返回表示出错,一般还会给出简单的出错提示。
11
12为了在服务器上使用命令,必须进行用户的登录。需要注意的是,输入的密码将会以明文的形式出现在终端屏幕上。正是由于会话过程中的明文传送,造成了早期的安全问题,所以后来专门对协议的鉴权产生了新的RFC。下面输入的命令字是USER和PASS,后面接着的分别是用户名和密码,由于是明文,所以采用<password>代替实际的输入。
13] User apexchu
14+OK core mail
15Pass <password>
16+OK 53 Message(s) [355846 byte(s)]
17可以看到,输入了正确的用户名和密码后,成功的登录到了服务器上并看到邮件数及总邮件大小[因邮件系统差异,结果可能不同,但POP3命令一样]。
18
19可以使用STAT命令察看邮箱的状态:
20]Stat
21+OK 53 355846
22这里的‘8’表示邮箱里有8封邮件,后面的数字表示这些邮件所占用的空间大小。
23
24可以使用LIST命令显示邮箱里所有的邮件列表:
25] List
26+OK 53 355846
271 23705
282 1663
293 10986
304 1559
315 528
326 10925
337 360
348 7927
359 1184
3610 756
3711 3212
3812 1209
3913 1313
4014 9495
4115 1225
4216 3155
4317 1384
4418 8942
4519 47017
4620 3787
4721 4612
4822 1101
4923 2335
5024 1069
5125 1736
5226 8977
5327 17423
5428 2835
5529 1241
5630 1349
5731 1192
5832 3382
5933 987
6034 455
6135 9769
6236 47644
6337 337
6438 9967
6539 9982
6640 10781
6741 2682
6842 1568
6943 402
7044 1132
7145 2956
7246 43869
7347 2368
7448 5126
7549 13336
7650 332
7751 1175
7852 346
7953 3048
80.
81//++++++++++++++++++++++++++++++++++++++++++++++++++++++//
82//如果没有邮件显示
83//] List
84// .
85//++++++++++++++++++++++++++++++++++++++++++++++++++++++//
86
87可以看到,分别列出了53封邮件的编号和大小。并同SMTP一样使用‘.’结束。
88下面我们试着使用Retr命令接收一封邮件:
89]Retr 13
90+OK 1313 octets
91Received: from 202.108.44.207 (unknown [222.109.115.225])
92by 192.168.1.207 (Coremail) with SMTP id MsDcX2HnlkGHBuoF.5
93for <[email protected]>; Sun, 14 Nov 2004 13:04:44 +0800 (CST)
94X-Originating-IP: [222.109.115.225]
95To: [email protected]
96Subject: fantastic
97Date: Sun, 14 Nov 2004 00:03:30 -0500
98From: "Anders Lyden" <[email protected]>
99Content-Type: text/plain;
100charset="iso-8859-1"
101Content-Transfer-Encoding: quoted-printable
102MIME-Version: 1.0
103Message-Id: <4196E76C.0E38A7.18012>
104
105The crew, perched in the ratlines, examined the horizon which contracted a=
106nd darkened by degrees!=20
107
108Re-ingnite the fire in your relationship
109It's time to lift your morale
110Take the pill for your manhood
111Wonder product that really works
112Expand your manhood with 20% thicker
113Gain up to 3 or 4 inches in length
114
115Take a look:
116http://www.betterchoice4u.info/vprx/?plk432adIJSDFjxcns
117
118This product has no side effects.
119No msg
120http://www.betterchoice4u.info/vprx/s.php
121
122To raise and support armies, but no appropriation of money to that use sha=
123ll be for a longer term than two years;=20. However, I was astonished at t=
124he manoeuvres of the frigate? To define and punish piracies and felonies c=
125ommitted on the high seas, and offenses against the law of nations;=20?=20
126
127.
128
129
130可以看出来,这是一封以HTML格式内容为主体的邮件,主题是:fantastic,正文是HTML格式的。由 [email protected] 发往 [email protected] 。 为了保持和重置与服务器的连接,可以使用NOOP和RSET命令:
131]Noop
132+OK
133
134Rset
135+OK core mail
136
137为了在下载邮件之前预览,可以只下载邮件的头部信息和前面部分,这时使用TOP命令:
138Top 13 1
139+OK core mail
140
141Received: from 202.108.44.207 (unknown [222.109.115.225])
142by 192.168.1.207 (Coremail) with SMTP id MsDcX2HnlkGHBuoF.5
143for < [email protected] >; Sun, 14 Nov 2004 13:04:44 +0800 (CST)
144X-Originating-IP: [222.109.115.225]
145To: [email protected]
146Subject: fantastic
147Date: Sun, 14 Nov 2004 00:03:30 -0500
148From: "Anders Lyden" < [email protected] >
149Content-Type: text/plain;
150charset="iso-8859-1"
151Content-Transfer-Encoding: quoted-printable
152MIME-Version: 1.0
153Message-Id: <4196E76C.0E38A7.18012>
154
155The crew, perched in the ratlines, examined the horizon which contracted a=
156nd darkened by degrees!=20
157
158
159.
160数字‘13’表示预览的邮件编号,‘1’表示预览一行正文。与前面RETR命令返回的数据相比较,可以看到只返回了邮件正文的第一行,并且以‘.’结束。
161
162服务器上使用UID来标明每一封邮件,为了查看UID,可以使用UIDL命令,可以在命令后指定邮件的编号,不加指定的话将显示邮箱里所有邮件的UID。
163Uidl
164+OK core mail
1651 1tbiMgP7RkESXJXMPAADsl
1662 1tbiMgP7RkESXJXMPAACsk
1673 1tbiMgP7RkESXJXMPAABsn
1684 1tbiMgP7RkESXJXMPAAAsm
1695 1tbiIRD6Rj-6PVchjQAAmO
1706 1tbiJw-3RkCeC7X6RQADsF
1717 1tbiJw-3RkCeC7X6RQACsE
1728 1tbiJw-3RkCeC7X6RQABsH
1739 1tbiJw-3RkCeC7X6RQAAsG
17410 1tbiGxb2Rj-6OGyR2gAAsn
17511 1tbiGxHyRj-6OFIjSQABs6
17612 1tbiGxXxDD-6OETRLgAAm1
17713 1tbiGxDxCz-6OEOn+gAAmS
17814 1tbiMgztRkESXGqXggAAsl
17915 1tbiFRHuRj-6PnB2QAAAmR
18016 1tbiMgDuRkESXGsnAQAEsc
18117 1tbiFQvuRj-6PnGHMQAAsK
18218 1tbiFQvwRj-6PnsIAQACsj
18319 1tbiJxDwRkCeC4UCYQABsz
18420 1tbiJxXwRkCeC4ixbAAAmE
18521 1tbiJxjwRkCeC4pYlgAAmY
18622 1tbiGxr0Rj-6OF0LPAAAmk
18723 1tbiGw70Rj-6OF7XnQAAmO
18824 1tbiJxX0RkCeC6gmrwAAm0
18925 1tbiJxj0RkCeC6hRjAAAmt
19026 1tbiGxj1Rj-6OGJwKQAAs2
19127 1tbiGw70Rj-6OGGKzAAAm9
19228 1tbiGxn1Rj-6OGIDUwAAs+
19329 1tbiGxf1DD-6OGJZyQAAm6
19430 1tbiJxb1RkCeC6iMEQAAsi
19531 1tbiGxv1Rj-6OGSuTwAAsL
19632 1tbiGxj0Rj-6OGE89AAAsl
19733 1tbiGxj1Rj-6OGJwKQABs3
19834 1tbiJw72rUCeC7VDjwAAme
19935 1tbiIRT9Rj-6PV6iZgAAss
20036 1tbiISX+Rj-6PV-8RAAAmj
20137 1tbiISb+hD-6PWBCVAAAmz
20238 1tbiIRkBRj-6PWgYPQAAsK
20339 1tbiIRkBRj-6PWgYPQABsL
20440 1tbiIRkBRj-6PWgYPQACsI
20541 1tbiIRkBRj-6PWgYPQADsJ
20642 1tbiISYCRj-6PWwMxQAAme
20743 1tbiISACRj-6PXKB2AAAsW
20844 1tbiISACRj-6PXKB2AABsX
20945 1tbiISACRj-6PXKB2AACsU
21046 1tbiFRAFRj-6Pt8EhQAAsj
21147 1tbiIRwGlz-6PYm4igAAmv
21248 1tbiISUIRj-6PY5eAwAAsh
21349 1tbiIRoJRj-6PZIIhQAAsT
21450 1tbiIQ8Jlz-6PZXnvQAAmH
21551 1tbiISIJRj-6PZX+rAAAsz
21652 1tbiISIJRj-6PZX+rAABsy
21753 1tbiISIJRj-6PZX+rAACsx
218.
219Uidl 13
220+OK 13 1tbiGxDxCz-6OEOn+gAAmS
221可以通过命令直接删除邮件,需要指定要删除的邮件的编号,该命令是DELE:
222]Dele 13
223+OK
224可使用QUIT命令退出会话:
225]Quit
226+OK core mail
227服务器会给出相应的退出成功的信息,证实已经成功退出会话</[email protected]></[email protected]></password></password></host></host></host>