Pop3½ÓÊÕÊý¾Ý£¬²Î¼û
http://www.aspalliance.com/chrisg/default.asp?article=93
¸Ä³Éc#´úÂ룬²¢ÐÞ¸ÄÁËһЩbug
Èç
1.ÓõÄÊÇASCII,²¢²»ÊʺϹúÄÚµÄÓʼþ¶ÁÈ¡
½â¾ö·½·¨£º¸ÄΪEncoding.GetEncoding(936)
2.GetResponse²¢²»ÊǶÂÈû·½Ê½£¬Ã»ÓÐÍêÈ«ÏÂÔØÊý¾Ý
½â¾ö·½·¨£ºÉèÖÃÒ»¸östrEnd±êÖ¾£¬À´ÅжÏÊÇ·ñ½áÊø
3.GetResponseÿ´Î¶¼Òª·µ»ØReceiveBufferSize³¤µÄÊý¾Ý
½â¾ö·½·¨£º¸ù¾Ý½ÓÊÕµ½Êý¾Ý³¤¶È£¬·µ»Ø»º³åÖеĶÔÓ¦³¤¶ÈµÄÊý¾Ý
µÈµÈ..
System.Net.Sockets.TcpClient tcpC;
System.Net.Sockets.NetworkStream netStream;
string SendCommand(string sToSend){
byte[] bData=Encoding.GetEncoding(936).GetBytes(sToSend+Environment.NewLine);
netStream.Write(bData,0,bData.Length);
return GetResponse();
}
string GetResponse(){
byte[] bData=new byte[tcpC.ReceiveBufferSize];
int iRec=netStream.Read(bData, 0, bData.Length);
return Encoding.GetEncoding(936).GetString(bData,0,iRec);
}
string ReadMail(string ps,string un,string pw){
tcpC=new System.Net.Sockets.TcpClient(ps,110);
netStream = tcpC.GetStream();
string strResponse=GetResponse();
string strNL=Environment.NewLine;
string strEnd=strNL+"."+strNL+"+OK "+strNL;
SendCommand("user "+un);
SendCommand("pass "+pw);
strResponse=SendCommand("stat");
int iCount=Int32.Parse(strResponse.Split(' ')[1]);
Response.Write(iCount + " Messages");
for(int i=1;i<iCount;i++)strResponse+=SendCommand("top "+i+" 0");
strResponse+=SendCommand("QUIT");
while(!strResponse.EndsWith(strEnd))strResponse+=GetResponse();
tcpC.Close();
return strResponse;
}
µ÷Ó÷½·¨£º
ReadMail(pop3Server,username,password)
ps.¼ò»¯ÁË´úÂ룬ȡÏûÁËһЩÒì³£µÄ²¶×½£¬ÊÇΪÁËÈôó¼Ò¿´µÃÇå³þÃ÷°×.
,| ×ÔÓÉ¹ã¸æÇø |
| ¡¡ |