views:

646

answers:

2

I'm looking for a way to monitor a GMail inbox for new e-mails. However, I want to avoid checking every few minutes and I'm looking for some sort of real-time notification. I've noticed that Outlook (and other IMAP-supporting clients) instantly show when there is a new e-mail, but unfortunately all .NET IMAP libraries seem to lack this functionality.

Does anyone know of an IMAP library that has this functionality? Or is there another way to be instantly notified of new message without doing some short-period polling?

+6  A: 

You need to handle IMAP IDLE.

This will notify you when new messages arrive, without constant polling (which is bad).


A very good, commercial .NET IMAP library is MailBee.Net. I used it for a small project a while back, and it seemed to handle things very well, and be fairly easy to work with. There may be others - just search in your library for sending the IDLE command or IDLE command handling, and you'll likely find something.

Reed Copsey
+1  A: 

Mail.dll supports IDLE. Here's the simplified sample:

using (Imap client = new Imap())
{
    client.ConnectSSL("imap.server.com");
    client.Login("[email protected]", "password");

    FolderStatus folderStatus = client.SelectInbox();
    Console.WriteLine("Total message count: {0}",
        folderStatus.MessageCount);

    while(true)
    {
        FolderStatus currentStatus = client.Idle();
        Console.WriteLine("Total message count: {0}",
                currentStatus.MessageCount);
        foreach(long uid in client.SearchFlag(Flag.Unseen))
        {
            IMail email = new MailBuilder().CreateFromEml(
                client.GetHeadersByUID(uid));
            Console.WriteLine(email.Subject);
        }
    }
    client.Close();
}

You can download Mail.dll at: http://www.lesnikowski.com/mail/

Also check out my blog for samples.

Please note that Mail.dll is a commercial product that I've created.

@Queops

Here are the reports from 2 online antivirus scanners:

www.viruschief.com

www.virustotal.com

Please note that VirusTotal is using Symantec scanner.

Pawel Lesnikowski
I tried downloading the installer of the Mail.dll but my Norton Antivirus promptly said this was some sort of virus/threat and IMMEDIATLY deleted it. Caution is advised.
Queops
"some sort of"? Can you be more precise? I have been using this component for a long time and from my perspective everything is OK with it. If I am right it is used also by big companies.
Marcin Obel