1
private void GetMail()
2
{
3
//连接邮件服务器
4
System.Net.Sockets.TcpClient TC = new System.Net.Sockets.TcpClient("pop.163.com", 110);
5
//发送用户名
6
byte[] A_Array = Encoding.ASCII.GetBytes("USER robbine111\r\n");
7
//发送密码
8
byte[] B_Array = Encoding.ASCII.GetBytes("PASS 201103\r\n");
9
//察看邮件列表:统计信息
10
byte[] C_Array = Encoding.ASCII.GetBytes("STAT\r\n");
11
//察看邮件列表:邮件数量和大小
12
byte[] D_Array = Encoding.ASCII.GetBytes("LIST\r\n");
13
//关闭连接
14
byte[] E_Array = Encoding.ASCII.GetBytes("QUIT\r\n");
15
//缓存数组
16
byte[] Buff = new byte[256];
17
//缓存字符串
18
string Buff_Str = "";
19
//读取计数
20
int i = 0;
21
//获取网络流
22
NetworkStream NS = TC.GetStream();
23
//写入第一条命令
24
NS.Write(A_Array, 0, A_Array.Length);
25
//读取响应
26
i = NS.Read(Buff, 0, 256);
27
//字节解码
28
Buff_Str += Encoding.UTF8.GetString(Buff, 0, i);
29
i = 0;
30
//刷新流
31
NS.Flush();
32
//写入第二条命令
33
NS.Write(B_Array, 0, B_Array.Length);
34
i = NS.Read(Buff, 0, 256);
35
//读取响应
36
Buff_Str += Encoding.UTF8.GetString(Buff, 0, i);
37
i = 0;
38
//刷新流
39
NS.Flush();
40
//写入第三条命令
41
NS.Write(C_Array, 0, C_Array.Length);
42
//读取大数据量
43
string MailCountMsg = "";
44
do
45
{
46
i = NS.Read(Buff, 0, 256);
47
MailCountMsg = Encoding.UTF8.GetString(Buff, 0, i);
48
Buff_Str += MailCountMsg;
49
} while (i >= 256);
50
获取所有的邮件
60
i = 0;
61
//分析邮件列表
62
NS.Write(D_Array, 0, D_Array.Length);
63
//读取邮件列表
64
do
65
{
66
i = NS.Read(Buff, 0, 256);
67
Buff_Str += Encoding.GetEncoding("GB2312").GetString(Buff, 0, i);
68
} while (i >= 256);
69
//写入结束命令
70
NS.Write(E_Array, 0, E_Array.Length);
71
NS.Close();
72
MailContentBox.AppendText(Buff_Str);
73
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

60

61

62

63

64

65

66

67

68

69

70

71

72

73
