C# 使用HigLabo通过http代理连接POP3
我正在使用创建电子邮件客户端。我还需要使用http代理。 但每次认证都会失败。 我在这里找到了基本代码: 这是我的密码:C# 使用HigLabo通过http代理连接POP3,c#,sockets,proxy,pop3,higlabo,C#,Sockets,Proxy,Pop3,Higlabo,我正在使用创建电子邮件客户端。我还需要使用http代理。 但每次认证都会失败。 我在这里找到了基本代码: 这是我的密码: 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
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");
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用higlab.Net;
使用HigLabo.Net.Pop3;
使用System.Net.Sockets;
使用系统线程;
命名空间控制台应用程序1
{
班级计划
{
静态POP3客户端pop;
静态插座;
静态void Main(字符串[]参数)
{
字符串proxyAddr=“112.241.212.104”;//这似乎起作用了
int proxyPort=8585;
字节[]缓冲区=新字节[25];
pop=新的POP3客户端(“PopClient”);
套接字=新套接字(AddressFamily.InterNetwork,
SocketType.Stream,
原型(Tcp);
Console.WriteLine(“连接到代理…”);
socket.Connect(proxyAddr、proxyPort);
Console.WriteLine(“连接到代理”);
Console.WriteLine(“发送数据包…”);
Send(Encoding.UTF8.GetBytes(“CONNECT pop.mail.yahoo.com:995 HTTP/1.1”);
Send(Encoding.UTF8.GetBytes(“”);
Console.WriteLine(“发送的数据包”);
控制台。WriteLine(“等待响应…”);
socket.Receive(缓冲区);
控制台写入线(“收到的数据包”);
Console.WriteLine(“经过的时间:+经过的时间+”秒”);
Console.WriteLine(“连接POP到插座…”);
如果(弹出连接(插座))
{
pop.Connect();
Console.WriteLine(“连接完成”);
}
其他的
{
控制台。写入线(“断开”);
断开连接();
返回;
}
Ssl=true;
pop.UserName=“电子邮件地址”;
pop.Password=“Password”;
pop.ServerName=“pop.gmail.com”;
pop.Port=995;
Console.WriteLine(“验证…”);
if(pop.Authenticate())
{
Console.WriteLine(“身份验证完成”);//永远不会出现在这里
GetMail();
}
其他的
{
Console.WriteLine(“身份验证失败”);//总是在这里出现
断开连接();
}
}
私有静态void GetMail()
{
HigLabo.Mime.MailMessage msg=pop.GetMessage(1);
Console.WriteLine(msg.BodyText);
}
静态无效断开连接()
{
控制台。写入线(“断开…”);
pop.Close();
socket.Close();
控制台。写入线(“断开”);
}
}
}
我也给了这个应用程序许可。
这里怎么了
还有其他/更好/更简单的方法吗?可能与其他库一起使用?这是错误的:
您要使用的内容\r\n在字符串中。这是错误的: