Yahoo IMAP secure connection, "The server has closed the connection"

0 votes
asked Aug 11, 2011 by RebexUser (120 points)
edited Aug 12, 2011

I'm getting this error while trying to get number of messages from Yahoo server. I'm doing it per message (i.e. login to yahoo, get list of messages, than later go through list and connect, log in and get it one by one. After some amount of calls (few hundreds) I'm starting to get those messages during login call. Once it's started I cannot log in back in. Here is s a snippet of code:

        using (Imap client = new Imap())
        {
            TlsParameters parameters = new TlsParameters();
            parameters.CertificateVerifier = new Verifier();
            client.Options = ImapOptions.UsePeekForGetMessage;

            client.Timeout = 600000;
            client.Connect(, , parameters, ImapSecurity.Implicit);

            client.Login(, , ImapAuthentication.Auto);

            var folder = client.GetFolderInfo();

            if (folder.IsSelectable)
            {
                client.SelectFolder();

                client.GetMessage(, );

                var message = client.GetMessageInfo(, ImapListFields.FullHeaders);

                return new Foo()
                {
                };
            }
        }
Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Aug 12, 2011 by Lukas Pokorny (102,130 points)
edited Aug 12, 2011

Does this mean you actually connect and log in again and again, once for each message? Most IMAP servers would not like such behavior - if the clients connects too many times within a short time interval, many IMAP servers might temporarily refuse additional connections, which appears to be what is going on with Yahoo as well. Why don't you only connect and log in once when downloading the messages? That would most likely solve the problem.

...