This project is read-only.

How do you use the IDLE commands?

Feb 1, 2011 at 4:23 PM
Edited Feb 1, 2011 at 4:24 PM

I've tried messing with the StartIdle/StopIdle, and added essentially the following, but it doesn't seem to work.  I've tested sending messages to the account while it's in start idle, in visual studio I see a console message saying * 13 Exists (or something like that) when I send a new message, so I know the library is aware a new message exists, but it's not calling my event handler.  Do I need to idle in a background thread?  Should I not subscribe?  My app is very simple, I just need to parse all unread messages and respond very quickly to the new messages.  Any delay at all is bad so IDLE seems like the solution.  I've tried a couple of the codeplex imap clients and none of them seem to have idle examples.


imap.ConnectSsl("", 993);          

imap.Login("", "xxxxxx");

Mailbox inbox = imap.SelectMailbox("INBOX");            

imap.NewMessageReceived += new NewMessageReceivedEventHandler(imap_NewMessageReceived);            





Feb 2, 2011 at 6:24 PM

I did get it to work by changing the library to call the event handler when it receives an "EXISTS" code in addition to "RECENT".  I looked at the imap spec and it should be RECENT, but the message I get from the server always says EXISTS.  I'm not sure exactly why but whatever, it's working for me now.

Apr 14, 2011 at 9:55 PM



I have the same need as andrewaggb;

I modified the library with the "EXISTS" and breakpoint hits when new message is received;

However, when I try to get the last message, with debugger step, it simply breaks (debugger is out, code is running but no new messages are received);


this is my code:

void client_NewMessageReceived(object sender, NewMessageReceivedEventArgs e)
            int offset = e.MessageCount - 2;
                // not working with or without comments
                Message message = Inbox.Fetch.MessageObject(offset);
                Debug.WriteLine("message subject: " + message.Subject);
            catch (Exception ex)

Please help...



Apr 20, 2011 at 2:49 PM

After also modifying the library with the "EXISTS" I got everything working by calling Client.StopIdle() in the client_NewMessageReceived method. That will resume execution in the method where you called Client.StartIdle(). Here's the example:



public void Execute(string configFilePath, string username, string password, string host, string outputDir)
            if (log.IsDebugEnabled)
                log.DebugFormat("Checking email...");

            stop = false;

                using (client = new Imap4Client())
                    client.NewMessageReceived += client_NewMessageReceived;
                    client.ConnectSsl(host, 993);
                    client.Login(username, password);

                    while (!stop)
                        if (log.IsDebugEnabled)
                            log.DebugFormat("Idle, waiting for new email notifications.");

                        if (stop)//this line will execute after client.StopIdle()

                        var folderStatus = client.SelectMailbox("Inbox");
                        if (folderStatus.MessageCount - emailConfig.LastEmailSequenceNumber <= 0) 

                        if (log.IsDebugEnabled)
                            log.DebugFormat("Picking up {0} new email(s).", folderStatus.MessageCount - emailConfig.LastEmailSequenceNumber);
                        PickupEmails(folderStatus, emailConfig.LastEmailSequenceNumber + 1, folderStatus.MessageCount, outputDir);
            catch (Exception ex)
                log.ErrorFormat("Error retrieving email:{0}", ex);              

void client_NewMessageReceived(object sender, NewMessageReceivedEventArgs e)



Jul 9, 2012 at 2:50 AM


You mention that <<I did get it to work by changing the library to call the event handler when it receives an "EXISTS" code in addition to "RECENT".  I looked at the imap spec and it should be RECENT, but the message I get from the server always says EXISTS.>>

Can you please specify how this is done and if possible??

An example of the whole working code would be valuable for me and the others who follow!

I have added the NewMessageReceivedEventHandler but is never called.. Instead I use the TcpReadEventHandler and when I receive a new email this is called but not only then.

I hope I will receive an answer from you!

Thank you in advance!

Nov 5, 2012 at 5:58 PM

Dec 10, 2014 at 4:09 PM

this code works fine for me with Gmail, but it doesn't work for Microsoft Exchange 2013. Login works fine, inbox selection and subscribe as well, but then the code is blocked in StartIdle() on line response = sr.ReadLine(), and doesn't react to any incoming email. Any idea?

Thank you,