POP3 Protocol

类别:.NET开发 点击:0 评论:0 推荐:
POP3 Protocol:
    POP3,即Post Office Protocol 3,3是它的版本,是目前使用的主流版本。到这篇文章出搞的时候,我参考的是RFC 1939 [Myers&Rose 1998],RFC 1734、RFC2195介绍了鉴权的内容,RFC 2449介绍了扩展内容。

    当你需要连接用“]”表示终一个POP3服务器,你可以使用如下的命令行。本文使端显示,<host>表示目标主机,可以是IP地址或者是有效的主机名。下面如没有特殊说明,都可认为如此表示:
] telnet <host> 110
    如果系统使用知名端口列表映射,则可以使用下面的命令行:
] telnet <host> pop3

    我们连接SMTP服务器:
] telnet pop3.163.com 110
    如果连接成功,服务器会返回如下信息:
] +OK Welcome to coremail Mail Pop3 Server(163com[20030606])
    可以看到返回了+OK的字样,表示成功地连接到了POP3服务器,POP3服务器使用+OK的返回表示命令成功执行,而用-ERR的返回表示出错,一般还会给出简单的出错提示。
   
    为了在服务器上使用命令,必须进行用户的登录。需要注意的是,输入的密码将会以明文的形式出现在终端屏幕上。正是由于会话过程中的明文传送,造成了早期的安全问题,所以后来专门对协议的鉴权产生了新的RFC。下面输入的命令字是USER和PASS,后面接着的分别是用户名和密码,由于是明文,所以采用<password>代替实际的输入。
] User apexchu  
  +OK core mail
  Pass <PASSWORD>
  +OK 53 Message(s) [355846 byte(s)]
    可以看到,输入了正确的用户名和密码后,成功的登录到了服务器上并看到邮件数及总邮件大小[因邮件系统差异,结果可能不同,但POP3命令一样]。
   
    可以使用STAT命令察看邮箱的状态:
]Stat
 +OK 53 355846
    这里的‘8’表示邮箱里有8封邮件,后面的数字表示这些邮件所占用的空间大小。
   
    可以使用LIST命令显示邮箱里所有的邮件列表:
] List
  +OK 53 355846
1 23705
2 1663
3 10986
4 1559
5 528
6 10925
7 360
8 7927
9 1184
10 756
11 3212
12 1209
13 1313
14 9495
15 1225
16 3155
17 1384
18 8942
19 47017
20 3787
21 4612
22 1101
23 2335
24 1069
25 1736
26 8977
27 17423
28 2835
29 1241
30 1349
31 1192
32 3382
33 987
34 455
35 9769
36 47644
37 337
38 9967
39 9982
40 10781
41 2682
42 1568
43 402
44 1132
45 2956
46 43869
47 2368
48 5126
49 13336
50 332
51 1175
52 346
53 3048
.
//++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//如果没有邮件显示
//] List
//  .
//++++++++++++++++++++++++++++++++++++++++++++++++++++++//

    可以看到,分别列出了53封邮件的编号和大小。并同SMTP一样使用‘.’结束。
下面我们试着使用Retr命令接收一封邮件:
]Retr 13
 +OK 1313 octets
 Received: from 202.108.44.207 (unknown [222.109.115.225])
        by 192.168.1.207 (Coremail) with SMTP id MsDcX2HnlkGHBuoF.5
        for <[email protected]>; Sun, 14 Nov 2004 13:04:44 +0800 (CST)
X-Originating-IP: [222.109.115.225]
To: [email protected]
Subject: fantastic
Date: Sun, 14 Nov 2004 00:03:30 -0500
From: "Anders Lyden" <[email protected]>
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Message-Id: <4196E76C.0E38A7.18012>

The crew, perched in the ratlines, examined the horizon which contracted a=
nd darkened by degrees!=20

Re-ingnite the fire in your relationship
It's time to lift your morale
Take the pill for your manhood
Wonder product that really works
Expand your manhood with 20% thicker
Gain up to 3 or 4 inches in length

Take a look:
http://www.betterchoice4u.info/vprx/?plk432adIJSDFjxcns

This product has no side effects.
No msg
http://www.betterchoice4u.info/vprx/s.php

To raise and support armies, but no appropriation of money to that use sha=
ll be for a longer term than two years;=20. However, I was astonished at t=
he manoeuvres of the frigate? To define and punish piracies and felonies c=
ommitted on the high seas, and offenses against the law of nations;=20?=20

.


    可以看出来,这是一封以HTML格式内容为主体的邮件,主题是:fantastic,正文是HTML格式的。由[email protected]发往[email protected]。    为了保持和重置与服务器的连接,可以使用NOOP和RSET命令:
]Noop
 +OK
 
 Rset
+OK core mail

为了在下载邮件之前预览,可以只下载邮件的头部信息和前面部分,这时使用TOP命令:
Top 13 1
+OK core mail

Received: from 202.108.44.207 (unknown [222.109.115.225])
        by 192.168.1.207 (Coremail) with SMTP id MsDcX2HnlkGHBuoF.5
        for <[email protected]>; Sun, 14 Nov 2004 13:04:44 +0800 (CST)
X-Originating-IP: [222.109.115.225]
To: [email protected]
Subject: fantastic
Date: Sun, 14 Nov 2004 00:03:30 -0500
From: "Anders Lyden" <[email protected]>
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Message-Id: <4196E76C.0E38A7.18012>

The crew, perched in the ratlines, examined the horizon which contracted a=
nd darkened by degrees!=20


.
    数字‘13’表示预览的邮件编号,‘1’表示预览一行正文。与前面RETR命令返回的数据相比较,可以看到只返回了邮件正文的第一行,并且以‘.’结束。
   
    服务器上使用UID来标明每一封邮件,为了查看UID,可以使用UIDL命令,可以在命令后指定邮件的编号,不加指定的话将显示邮箱里所有邮件的UID。
Uidl
+OK core mail
1 1tbiMgP7RkESXJXMPAADsl
2 1tbiMgP7RkESXJXMPAACsk
3 1tbiMgP7RkESXJXMPAABsn
4 1tbiMgP7RkESXJXMPAAAsm
5 1tbiIRD6Rj-6PVchjQAAmO
6 1tbiJw-3RkCeC7X6RQADsF
7 1tbiJw-3RkCeC7X6RQACsE
8 1tbiJw-3RkCeC7X6RQABsH
9 1tbiJw-3RkCeC7X6RQAAsG
10 1tbiGxb2Rj-6OGyR2gAAsn
11 1tbiGxHyRj-6OFIjSQABs6
12 1tbiGxXxDD-6OETRLgAAm1
13 1tbiGxDxCz-6OEOn+gAAmS
14 1tbiMgztRkESXGqXggAAsl
15 1tbiFRHuRj-6PnB2QAAAmR
16 1tbiMgDuRkESXGsnAQAEsc
17 1tbiFQvuRj-6PnGHMQAAsK
18 1tbiFQvwRj-6PnsIAQACsj
19 1tbiJxDwRkCeC4UCYQABsz
20 1tbiJxXwRkCeC4ixbAAAmE
21 1tbiJxjwRkCeC4pYlgAAmY
22 1tbiGxr0Rj-6OF0LPAAAmk
23 1tbiGw70Rj-6OF7XnQAAmO
24 1tbiJxX0RkCeC6gmrwAAm0
25 1tbiJxj0RkCeC6hRjAAAmt
26 1tbiGxj1Rj-6OGJwKQAAs2
27 1tbiGw70Rj-6OGGKzAAAm9
28 1tbiGxn1Rj-6OGIDUwAAs+
29 1tbiGxf1DD-6OGJZyQAAm6
30 1tbiJxb1RkCeC6iMEQAAsi
31 1tbiGxv1Rj-6OGSuTwAAsL
32 1tbiGxj0Rj-6OGE89AAAsl
33 1tbiGxj1Rj-6OGJwKQABs3
34 1tbiJw72rUCeC7VDjwAAme
35 1tbiIRT9Rj-6PV6iZgAAss
36 1tbiISX+Rj-6PV-8RAAAmj
37 1tbiISb+hD-6PWBCVAAAmz
38 1tbiIRkBRj-6PWgYPQAAsK
39 1tbiIRkBRj-6PWgYPQABsL
40 1tbiIRkBRj-6PWgYPQACsI
41 1tbiIRkBRj-6PWgYPQADsJ
42 1tbiISYCRj-6PWwMxQAAme
43 1tbiISACRj-6PXKB2AAAsW
44 1tbiISACRj-6PXKB2AABsX
45 1tbiISACRj-6PXKB2AACsU
46 1tbiFRAFRj-6Pt8EhQAAsj
47 1tbiIRwGlz-6PYm4igAAmv
48 1tbiISUIRj-6PY5eAwAAsh
49 1tbiIRoJRj-6PZIIhQAAsT
50 1tbiIQ8Jlz-6PZXnvQAAmH
51 1tbiISIJRj-6PZX+rAAAsz
52 1tbiISIJRj-6PZX+rAABsy
53 1tbiISIJRj-6PZX+rAACsx
.
 Uidl 13
 +OK 13 1tbiGxDxCz-6OEOn+gAAmS    
    可以通过命令直接删除邮件,需要指定要删除的邮件的编号,该命令是DELE:
]Dele 13
 +OK    
可使用QUIT命令退出会话:
]Quit
 +OK core mail
    服务器会给出相应的退出成功的信息,证实已经成功退出会话

本文地址:http://com.8s8s.com/it/it42409.htm