【问题标题】:connecting POP3 via http proxy using HigLabo使用 HigLabo 通过 http 代理连接 POP3
【发布时间】:2014-12-01 05:21:33
【问题描述】:

我正在使用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");
    }
}

}

我也授予了该应用程序的权限。 这里有什么问题?

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

【问题讨论】:

  • 这是错误的:

标签: c# sockets proxy pop3 higlabo


【解决方案1】:

这是错误的:.

您想要使用的是字符串中的 \r\n。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-30
    • 1970-01-01
    • 2016-05-23
    • 1970-01-01
    • 2015-03-14
    • 2013-07-05
    • 1970-01-01
    相关资源
    最近更新 更多