C#。使用WebClient或HttpClient的POP3客户端

C#。使用WebClient或HttpClient的POP3客户端,c#,http,pop3,C#,Http,Pop3,我尝试从邮箱接收邮件。我发现如何使用tcp客户端执行此操作: static void Receive() { using (TcpClient client = new TcpClient ("mail.isp.com ", 110)) using (NetworkStream n = client.GetStream()) { ReadLine (n); // Read the welcome me

我尝试从邮箱接收邮件。我发现如何使用tcp客户端执行此操作:

static void Receive()
{
    using (TcpClient client = new TcpClient ("mail.isp.com ", 110))
    using (NetworkStream n = client.GetStream())
    {
        ReadLine (n);                             // Read the welcome message.
        SendCommand (n, "USER username");
        SendCommand (n, "PASS password");
        SendCommand (n, "LIST");                  // Retrieve message IDs
        List<int> messageIDs = new List<int>();
        while (true)
        {
            string line = ReadLine (n);             // e.g.  "1 1876"
            if (line == ".") break;
            messageIDs.Add (int.Parse (line.Split (' ')[0] ));   // Message ID
        }

        foreach (int id in messageIDs)         // Retrieve each message.
        {
            SendCommand (n, "RETR " + id);
            string randomFile = Guid.NewGuid().ToString() + ".eml";
            using (StreamWriter writer = File.CreateText (randomFile))
            while (true)
            {
                string line = ReadLine (n);      // Read next line of message.
                if (line == ".") break;          // Single dot = end of message.
                if (line == "..") line = ".";    // "Escape out" double dot.
                writer.WriteLine (line);         // Write to output file.
            }
            SendCommand (n, "DELE " + id);       // Delete message off server.
        }
        SendCommand (n, "QUIT");
    }
}
static void Receive()
{
使用(TcpClient client=newtcpclient(“mail.isp.com”,110))
使用(NetworkStream n=client.GetStream())
{
ReadLine(n);//阅读欢迎信息。
SendCommand(n,“用户用户名”);
SendCommand(n,“传递密码”);
SendCommand(n,“LIST”);//检索消息ID
List messageIDs=new List();
while(true)
{
string line=ReadLine(n);//例如“1 1876”
如果(直线=“=”)中断;
messageid.Add(int.Parse(line.Split(“”)[0]);//消息ID
}
foreach(messageIDs中的int-id)//检索每条消息。
{
SendCommand(n,“RETR”+id);
字符串randomFile=Guid.NewGuid().ToString()+“.eml”;
使用(StreamWriter writer=File.CreateText(随机文件))
while(true)
{
string line=ReadLine(n);//读取消息的下一行。
if(line==“)break;//单点=消息结束。
如果(line==“.”)line=“.”;/“退出”双点。
writer.WriteLine(行);//写入输出文件。
}
SendCommand(n,“DELE”+id);//从服务器上删除消息。
}
SendCommand(n,“退出”);
}
}
如何使用web请求接收邮件?
我需要使用http客户端执行此操作。

谢谢大家!

您可能可以使用WebClient实现这一点,但您确实意识到HTTP客户端是用于HTTP/S而不是POP3的,对吗?WebClient抽象了ftp和HTTP协议;httpclient,http。“Pop3不是这些协议中的任何一个。”乔丹·麦奎根,是的。我现在不知道如何使用电子邮件接收邮件WebClient@Peter里奇,我明白了。我想使用WebClient类或HttpClient实现简单的操作,比如读取邮件、从gmail中删除邮件(例如)class@user3443227你不能,POP3不是基于HTTP的,为什么不使用像这样的库呢