C#恒定流pop3
好吧,我遇到了一个问题,我以为我用一个蹩脚的钻机解决了,但从长远来看它失败了,所以我来问你们正确的方法。这是我遇到的问题,我正在制作一个应用程序,通过POP3(使用ActiveUp api)过滤掉某种类型的电子邮件,但我需要它与POP3服务器保持稳定的连接……这就是我现在拥有的:C#恒定流pop3,c#,c#-4.0,pop3,C#,C# 4.0,Pop3,好吧,我遇到了一个问题,我以为我用一个蹩脚的钻机解决了,但从长远来看它失败了,所以我来问你们正确的方法。这是我遇到的问题,我正在制作一个应用程序,通过POP3(使用ActiveUp api)过滤掉某种类型的电子邮件,但我需要它与POP3服务器保持稳定的连接……这就是我现在拥有的: public static void Main (string[] args) { while(true) { POP3();
public static void Main (string[] args)
{
while(true)
{
POP3();
Console.Title = "Waiting for "+GetSubject+POST;
Thread.Sleep(5000);
}
}
public static void POP3()
{
Pop3Client pop3 = new Pop3Client();
try
{
pop3.ConnectSsl("pop.gmail.com",995,"", "");
if(pop3.MessageCount > 0)
{
int CurrentMessage = pop3.MessageCount;
ActiveUp.Net.Mail.Message message = pop3.RetrieveMessageObject(CurrentMessage);
if(message.Subject == GetSubject+POST)
{
Console.WriteLine("command reconized from {0}: {1}\n Sending responce now!",message.From.Email, message.Subject);
SMTP (message.From.Email, _message);
POST++;
pop3.Close();
}
}
else
{
Console.WriteLine("no mail found");
}
}
catch(Pop3Exception iex)
{
Console.WriteLine(iex);
pop3.Close();
}
}
在它运行10-20分钟之前,一切都很完美。我被谷歌的POP3服务器踢出,不得不重新启动应用程序。我现在运行应用程序,用错误重新编辑我的问题。但在那之前,你们能帮我吗?谢谢
错误:
nhandled Exception: System.Net.Sockets.SocketException: No such host is known
at System.Net.Dns.hostent_to_IPHostEntry (System.String h_name, System.String[] h_aliases, System.String[] h_addrlist) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostByName (System.String hostName) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.String hostname, Int32 port) [0x00000] in <filename unknown>:0
at ActiveUp.Net.Mail.Pop3Client.ConnectSsl (System.String host, Int32 port, System.String user, System.String pass, ActiveUp.Net.Security.SslHandShake sslHandShake) [0x00000] in <filename unknown>:0
at ActiveUp.Net.Mail.Pop3Client.ConnectSsl (System.String host, Int32 port, System.String user, System.String pass) [0x00000] in <filename unknown>:0
at AutoThreadOwnerCopy.MainClass.POP3 () [0x00006] in /home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs:35
at AutoThreadOwnerCopy.MainClass.Main (System.String[] args) [0x00019] in /home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs:25
[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Sockets.SocketException: No such host is known
at System.Net.Dns.hostent_to_IPHostEntry (System.String h_name, System.String[] h_aliases, System.String[] h_addrlist) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostByName (System.String hostName) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpClient.Connect (System.String hostname, Int32 port) [0x00000] in <filename unknown>:0
at ActiveUp.Net.Mail.Pop3Client.ConnectSsl (System.String host, Int32 port, System.String user, System.String pass, ActiveUp.Net.Security.SslHandShake sslHandShake) [0x00000] in <filename unknown>:0
at ActiveUp.Net.Mail.Pop3Client.ConnectSsl (System.String host, Int32 port, System.String user, System.String pass) [0x00000] in <filename unknown>:0
at AutoThreadOwnerCopy.MainClass.POP3 () [0x00006] in /home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs:35
at AutoThreadOwnerCopy.MainClass.Main (System.String[] args) [0x00019] in /home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs:25
n已处理的异常:System.Net.Sockets.SocketException:未知此类主机
在System.Net.Dns.hostent_至_IPHostEntry(System.String h_名称,System.String[]h_别名,System.String[]h_地址列表)[0x00000]中:0
位于:0中的System.Net.Dns.GetHostByName(System.String主机名)[0x00000]处
位于:0中的System.Net.Dns.GetHostEntry(System.String主机名或地址)[0x00000]处
位于:0中的System.Net.Dns.GetHostAddresses(System.String hostNameOrAddress)[0x00000]处
在System.Net.Sockets.TcpClient.Connect(System.String主机名,Int32端口)[0x00000]中:0
在ActiveUp.Net.Mail.Pop3Client.ConnectSsl(System.String主机、Int32端口、System.String用户、System.String密码、ActiveUp.Net.Security.SslHandShake SslHandShake)[0x00000]中:0
在ActiveUp.Net.Mail.Pop3Client.ConnectSsl(System.String主机、Int32端口、System.String用户、System.String密码)[0x00000]中:0
在/home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs:35中的AutoThreadOwnerCopy.MainClass.POP3()[0x00006]处
在/home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs中的AutoThreadOwnerCopy.MainClass.Main(System.String[]args)[0x00019]处
[错误]致命的未处理异常:System.Net.Sockets.SocketException:未知此类主机
在System.Net.Dns.hostent_至_IPHostEntry(System.String h_名称,System.String[]h_别名,System.String[]h_地址列表)[0x00000]中:0
位于:0中的System.Net.Dns.GetHostByName(System.String主机名)[0x00000]处
位于:0中的System.Net.Dns.GetHostEntry(System.String主机名或地址)[0x00000]处
位于:0中的System.Net.Dns.GetHostAddresses(System.String hostNameOrAddress)[0x00000]处
在System.Net.Sockets.TcpClient.Connect(System.String主机名,Int32端口)[0x00000]中:0
在ActiveUp.Net.Mail.Pop3Client.ConnectSsl(System.String主机、Int32端口、System.String用户、System.String密码、ActiveUp.Net.Security.SslHandShake SslHandShake)[0x00000]中:0
在ActiveUp.Net.Mail.Pop3Client.ConnectSsl(System.String主机、Int32端口、System.String用户、System.String密码)[0x00000]中:0
在/home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs:35中的AutoThreadOwnerCopy.MainClass.POP3()[0x00006]处
在/home/m44m31/AutoThreadOwnerCopy/AutoThreadOwnerCopy/Main.cs中的AutoThreadOwnerCopy.MainClass.Main(System.String[]args)[0x00019]处