Looking for a real-time IMAP notification of new E

2019-02-09 08:06发布

问题:

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?

回答1:

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.



回答2:

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

using (Imap client = new Imap())
{
    client.ConnectSSL("imap.server.com");
    client.Login("user@server.com", "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.



回答3:

Try free .NET library for accessing IMAP server S22.Imap, with IDLE support