C# 无法建立连接,因为目标计算机主动拒绝了它74.125.25.109:993
您好,我正在尝试使用C中的ImapX库连接到gmail。 但是,由于在ImapX内创建TcpClient时,目标计算机主动拒绝了74.125.25.109:993,因此无法建立连接。 我浏览了几个关于stackoverflow的相同问题,但没有一个对我有帮助 这是我的密码C# 无法建立连接,因为目标计算机主动拒绝了它74.125.25.109:993,c#,imap,tcpclient,gmail-imap,imapx,C#,Imap,Tcpclient,Gmail Imap,Imapx,您好,我正在尝试使用C中的ImapX库连接到gmail。 但是,由于在ImapX内创建TcpClient时,目标计算机主动拒绝了74.125.25.109:993,因此无法建立连接。 我浏览了几个关于stackoverflow的相同问题,但没有一个对我有帮助 这是我的密码 static void Main(string[] args) { var client = new ImapClient("imap.gmail.com",993, true); client.SslProt
static void Main(string[] args)
{
var client = new ImapClient("imap.gmail.com",993, true);
client.SslProtocol = System.Security.Authentication.SslProtocols.Ssl2;
client.UseSsl = true;
if (client.Connect()) // This method creates new instance of TcpClient which throws error so returning false from catch block method has been described below.
{
if (client.Login("example@gmail.com", "example123"))
{
// login successful
}
Console.WriteLine("Connection Successful...!");
Console.ReadLine();
}
else
{
Console.WriteLine("Connection UnSuccessful...!");
Console.ReadLine();
// connection not successful
}
}
下面是ImapX库中的客户机方法
public bool Connect(string host, int port, SslProtocols sslProtocol = SslProtocols.None,
bool validateServerCertificate = true)
{
_host = host;
_port = port;
_sslProtocol = sslProtocol;
_validateServerCertificate = validateServerCertificate;
if (IsConnected)
throw new InvalidStateException("The client is already connected. Please disconnect first.");
try
{
_client = new TcpClient(_host, _port);
if (_sslProtocol == SslProtocols.None)
{
_ioStream = _client.GetStream();
_streamReader = new StreamReader(_ioStream);
}
else
{
_ioStream = new SslStream(_client.GetStream(), false, CertificateValidationCallback, null);
(_ioStream as SslStream).AuthenticateAsClient(_host, null, _sslProtocol, false);
_streamReader = new StreamReader(_ioStream);
}
string result = _streamReader.ReadLine();
_lastActivity = DateTime.Now;
if (result != null && result.StartsWith(ResponseType.ServerOk))
{
Capability();
return true;
}
else if (result != null && result.StartsWith(ResponseType.ServerPreAuth))
{
IsAuthenticated = true;
Capability();
return true;
}
else
return false;
}
catch (Exception)
{
return false;
}
finally
{
if (!IsConnected)
CleanUp();
}
}
提前感谢。当您将ImapX与GMail一起使用时,以下代码足以建立连接:
var client = new ImapClient("imap.gmail.com", true);
if (client.Connect()) {
// ...
}
它将使用标准993端口的SSL。如果您想手动指定SSL版本,那么对于GMail,您需要使用SslProtocols.Default,它相当于SslProtocols.Ssl3 | SslProtocols.Tls如果我使用Telenet,那么我就是这样。Microsoft Telnet>打开imap.gmail.com 993连接到imap.gmail.com…无法打开到主机的连接,端口99 3:连接失败您是否能够连接到某些邮件客户端软件,如thunderbird?您是否配置了任何代理?@FrantišekŽiačik我对thunderbird不太清楚,我使用Windows Live mail作为我的邮件客户端,并且没有配置任何代理。您尝试过不同的协议吗?类似client.SslProtocol=System.Security.Authentication.SslProtocols.Default。我希望SSl2是好的,但你永远不知道。有人在阻止你。可能是你的防火墙。可以通过代理。可能是你的反恶意软件。可能是谷歌,因为你的IP地址被用来发送太多的垃圾邮件。你是对的。问题是我的机器和网络不允许我通过端口993连接到imap.gmail.com。我试着用另一台机器,它开始工作了。谢谢你抽出时间。