using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Net.Mail;
using System.Net;
using System.IO;
namespace Email.POP3
{ public class POP3 {
public static int _Closed=0;
public static int _Connected=1;
public static int _Trandsaction=2;
public static int _Finished=9; private TcpClient client;
private NetworkStream stream;
private int state=_Closed;
public POP3() { } private string info = null;
public string Info {
get { return info; }
}
public bool Connect() {
client = new TcpClient("pop3.163.com", 110);
stream = client.GetStream();
bool flag = false;
string response=ReceiveResponse();
string repmsg="\n服务器响应:"+response+"\n";
info = repmsg;
if(repmsg.IndexOf("OK")>=0 || repmsg.IndexOf("220")>=0) {
flag= true;
}
return flag;
} private string ReceiveResponse() {
byte[] bb = new byte[512];
try
{
int len = stream.Read(bb, 0, bb.Length);
string read = System.Text.Encoding.UTF8.GetString(bb);
return read.Substring(0, len);
}
catch (Exception e)
{
throw new ArgumentException(e.ToString());
}
} public void Pop3Login() {
string response=null;
string repmsg = null; SendCommand("USER swat");
response=ReceiveResponse();
repmsg += "验证用户..." + response + "\n";
if (response.IndexOf("OK") < 0) {
repmsg += "用户名错误!";
return ;
} SendCommand("PASS 123");
response = ReceiveResponse();
repmsg += "验证密码..." + response + "\n"; if (response.IndexOf("OK") < 0) {
repmsg += "密码错误!";
info = repmsg;
return ;
} repmsg += "成功登录服务器\n";
info = repmsg;
} private void SendCommand(string command) {
try
{
string stringToSend = command + "\r\n";
byte[] arrayToSend = System.Text.Encoding.Default.GetBytes(stringToSend.ToCharArray());
stream.Write(arrayToSend, 0, arrayToSend.Length);
stream.Flush();
// stream.cl
}
catch (Exception)
{
throw;
}
}
}
}
写了这样一个类,但是到密码验证部分总提示不正确(在这里我就不公开我的邮箱名称和密码,分别用swat,123代替,如果有朋友使用这个帮我进行测试时,请记得修改). 验证用户...+OK core mail
验证密码...-ERR ???????????pop3????
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Net.Mail;
using System.Net;
using System.IO;
namespace Email.POP3
{ public class POP3 {
public static int _Closed=0;
public static int _Connected=1;
public static int _Trandsaction=2;
public static int _Finished=9; private TcpClient client;
private NetworkStream stream;
private int state=_Closed;
public POP3() { } private string info = null;
public string Info {
get { return info; }
}
public bool Connect() {
client = new TcpClient("pop3.163.com", 110);
stream = client.GetStream();
bool flag = false;
string response=ReceiveResponse();
string repmsg="\n服务器响应:"+response+"\n";
info = repmsg;
if(repmsg.IndexOf("OK")>=0 || repmsg.IndexOf("220")>=0) {
flag= true;
}
return flag;
} private string ReceiveResponse() {
byte[] bb = new byte[512];
try
{
int len = stream.Read(bb, 0, bb.Length);
string read = System.Text.Encoding.UTF8.GetString(bb);
return read.Substring(0, len);
}
catch (Exception e)
{
throw new ArgumentException(e.ToString());
}
} public void Pop3Login() {
string response=null;
string repmsg = null; SendCommand("USER swat");
response=ReceiveResponse();
repmsg += "验证用户..." + response + "\n";
if (response.IndexOf("OK") < 0) {
repmsg += "用户名错误!";
return ;
} SendCommand("PASS 123");
response = ReceiveResponse();
repmsg += "验证密码..." + response + "\n"; if (response.IndexOf("OK") < 0) {
repmsg += "密码错误!";
info = repmsg;
return ;
} repmsg += "成功登录服务器\n";
info = repmsg;
} private void SendCommand(string command) {
try
{
string stringToSend = command + "\r\n";
byte[] arrayToSend = System.Text.Encoding.Default.GetBytes(stringToSend.ToCharArray());
stream.Write(arrayToSend, 0, arrayToSend.Length);
stream.Flush();
// stream.cl
}
catch (Exception)
{
throw;
}
}
}
}
写了这样一个类,但是到密码验证部分总提示不正确(在这里我就不公开我的邮箱名称和密码,分别用swat,123代替,如果有朋友使用这个帮我进行测试时,请记得修改). 验证用户...+OK core mail
验证密码...-ERR ???????????pop3????
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货