jstedfast / MailKit

A cross-platform .NET library for IMAP, POP3, and SMTP.
http://www.mimekit.net
MIT License
6.22k stars 824 forks source link

System.Net.Sockets.SocketException (10060) #1682

Closed devsienko closed 11 months ago

devsienko commented 11 months ago

I get the follow error: System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

Platform (please complete the following information):

Exception System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state) --- End of stack trace from previous location --- at System.Threading.Tasks.TaskToAsyncResult.End(IAsyncResult asyncResult) at MailKit.Net.SocketUtils.ConnectAsync(String host, Int32 port, IPEndPoint localEndPoint, CancellationToken cancellationToken) at MailKit.Net.SocketUtils.ConnectAsync(String host, Int32 port, IPEndPoint localEndPoint, Int32 timeout, CancellationToken cancellationToken) at MailKit.MailService.ConnectNetworkAsync(String host, Int32 port, CancellationToken cancellationToken) at MailKit.Net.Smtp.SmtpClient.ConnectAsync(String host, Int32 port, SecureSocketOptions options, CancellationToken cancellationToken) at Microsender.MailServer.SmtpService.Send(MimeMessage message) in C:\Source\microsender\backend\smtp-server\Microsender.MailServer\SmtpService.cs:line 76

To Reproduce

using var client = new MailKit.Net.Smtp.SmtpClient();
client.ServerCertificateValidationCallback = (_, _, _, _) =>
{
    //_logger...
    return true;
};
await client.ConnectAsync(smtpEndpoint.Url, 25);
// await client.SendAsync(message)...

Additional context I installed smtp4dev on an remove machine and await client.ConnectAsync(smtpEndpoint.Url, 25) worked fine, but if I try to send an email to gmail or any other services, even mail-tester.com I get this error.

I cheked ip address and port by telnet, they are available.

jstedfast commented 11 months ago

I don't think this bug has anything to do with MailKit. I 99% positive that you'd get the exact same exception trying to make a Socket connection to the host/port without any involvement from MailKit.

using var client = new MailKit.Net.Smtp.SmtpClient();
client.ServerCertificateValidationCallback = (_, _, _, _) =>
{
    //_logger...
    return true;
};

var socket = new System.Net.Sockets.Socket(System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
await socket.ConnectAsync(smtpEndpoint.Url, 25);

await client.ConnectAsync(socket, smtpEndpoint.Url, 25);
devsienko commented 11 months ago

You are right, sorry for disturbing:)