MailKit icon indicating copy to clipboard operation
MailKit copied to clipboard

IMAP connection losing automatically

Open SumitDobhal opened this issue 8 years ago • 5 comments

I was using MailKit to get notification and read new mails. But faced problems when I tried using it for long interval of time.

  1. The connection was lost sometimes without any logs ; (ProtocolLogger(Console.OpenStandardError()))
  2. The connection was lost with some logs saying "Outlook signing off " (Don't have exact error right now)

So I am connecting my Outlook office email using MailKit with timer being set as 9 minutes.

I am not able to figure it out why my connection is losing automatically.

SumitDobhal avatar May 22 '18 03:05 SumitDobhal

IMAP servers can disconnect you for any reason at any time. Typically, they will hold a connection open for at least 10 minutes but I have found that to not always hold true. GMail, for example, will almost always kick me off if my client idles for more than somewhere around 9 minutes.

You just have to handle re-connecting when that happens.

That said, have you tried lowering your interval to, say, 5 minutes instead of 10?

jstedfast avatar May 22 '18 14:05 jstedfast

I tried reducing the interval to 5 minutes I was connected for almost 6 hours . But than IMAP server stopped sending me any events. I understood you said to re-connect again .But what should be the proper way to connect to the IMAP servers again? Is there any exception handling method / event to handle this type of disconnection where the IMAP server stops sending you any response?

SumitDobhal avatar May 24 '18 09:05 SumitDobhal

Yes.

Catch ImapProtocolException exceptions and then you can check client.IsConnected to see if you need to reconnect or not.

I think the Disconnected event also gets emitted, but I'm less sure on that offhand.

jstedfast avatar May 24 '18 13:05 jstedfast

I tried to do handle the exceptions but still didn't received anything in the exception. I got this message from the log "Microsoft Exchange Server IMAP4 Signing Off". But still not able to catch the exception.

SumitDobhal avatar May 31 '18 06:05 SumitDobhal

You will get an ImapProtocolException the next time you attempt to send a command.

jstedfast avatar May 31 '18 15:05 jstedfast