使用 HigLabo 通过 http 代理连接 POP3

本文关键字:连接 POP3 代理 http HigLabo 通过 使用 | 更新日期: 2023-09-27 18:32:30

我正在使用HigLabo创建一个电子邮件客户端。我还需要使用 http 代理。但身份验证每次都失败。我在这里找到了基本代码:.net pop3 over http proxy

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HigLabo.Net;
using HigLabo.Net.Pop3;
using System.Net.Sockets;
using System.Threading;
namespace ConsoleApplication1
{
    class Program
    {
        static Pop3Client pop;
        static Socket socket;
    static void Main(string[] args)
    {
        String proxyAddr = "112.241.212.104"; //This seemed to be working
        int proxyPort = 8585;
        byte[] buffer = new byte[25];
        pop = new Pop3Client("PopClient");
        socket = new Socket(AddressFamily.InterNetwork,
                                     SocketType.Stream,
                                     ProtocolType.Tcp);
        Console.WriteLine("Connecting to proxy...");
        socket.Connect(proxyAddr, proxyPort);
        Console.WriteLine("Connected to proxy");
        Console.WriteLine("Sending Packets...");
        socket.Send(Encoding.UTF8.GetBytes("CONNECT pop.mail.yahoo.com:995 HTTP/1.1<CR><LF>"));
        socket.Send(Encoding.UTF8.GetBytes("<CR><LF>"));
        Console.WriteLine("Packets sent");
        Console.WriteLine("Waiting for response...");
        socket.Receive(buffer);
        Console.WriteLine("Packets received");
        Console.WriteLine("Time Elapsed : " + timeElapsed + " seconds");
        Console.WriteLine("Connectong POP to socket...");
        if (pop.Connect(socket)) 
        {
            pop.Connect();
            Console.WriteLine("Connection completed");
        }
        else
        {
            Console.WriteLine("Disconnected");
            Disconnect();
            return;
        }
        pop.Ssl = true;
        pop.UserName = "EMAIL_ADDRESS";
        pop.Password = "PASSWORD";
        pop.ServerName = "pop.gmail.com";
        pop.Port = 995;
        Console.WriteLine("Authenticating...");
        if (pop.Authenticate())
        {
            Console.WriteLine("Authentication completed"); //Never comes here
            GetMail();
        }
        else
        {
            Console.WriteLine("Authentication failed"); //Always comes here
            Disconnect();
        }

    }
    private static void GetMail()
    {
        HigLabo.Mime.MailMessage msg = pop.GetMessage(1);
        Console.WriteLine(msg.BodyText);
    }
    static void Disconnect()
    {            
        Console.WriteLine("Disconnecting...");
        pop.Close();
        socket.Close();
        Console.WriteLine("Disconnected");
    }
}

}

我也允许该应用程序。这是怎么回事?

还有其他/更好/简单的方法可以做到这一点吗?可能使用不同的库?

使用 HigLabo 通过 http 代理连接 POP3

这是

错误的:

要使用的是字符串中的 ''r'。