Eyup Can ARSLAN
Eyup Can ARSLAN

Reputation: 742

System.IO.IOException: Connection timed out In Mailkit

I used MailKit.Net.Imap to read email in my mail box.

Sometimes I get an exception like that I shared below

System.IO.IOException: Connection timed out ---> System.Net.Sockets.SocketException (110): Connection timed out at MailKit.Net.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count) --- End of inner exception stack trace ---

Is there any suggistion to solve this problem?

   ImapClient client;
  
    client = new ImapClient();
    client.Timeout= (int)TimeSpan.FromMinutes(1).TotalMilliseconds;

Also, I can use timeout property of Imap, this can help me to solve this problem?

Upvotes: 0

Views: 1224

Answers (1)

jstedfast
jstedfast

Reputation: 38538

You have 2 options:

  1. Increase the timeout using the ImapClient.Timeout property. (That said, 1 minute is less than the default timeout which is 2 minutes)
  2. As Max points out in the comments below, properly handle exceptions and retry (which often will require reconnecting the ImapClient).

Upvotes: 1

Related Questions