i have been searching all over the place for a way to get the count of unread emails in my Gmail account using GemBox.Email.Imap. So far i am able to connect, get the count of all mails but i need just the unread, is there anyone that have some experience using this Package?.
Gembox.Email.Imap get the count of unread mails
414 Views Asked by AcidRod75 At
2
There are 2 best solutions below
0

Okay, after a little bit i found out how to make this work, this is the code for a simple console aplication but it is extensible for any case.
using System;
using System.Collections.Generic;
using GemBox.Email;
using GemBox.Email.Imap;
namespace IMapAccess
{
class Program
{
static void Main(string[] args)
{
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
using (ImapClient imap = new ImapClient("imap.gmail.com", 993)){
imap.ConnectTimeout = TimeSpan.FromSeconds(10);
imap.Connect();
imap.Authenticate("[email protected]", "MySuperSecretPassword", ImapAuthentication.Native);
imap.SelectInbox();
IList<int> messages = imap.SearchMessageNumbers("UNSEEN");
Console.WriteLine($"Number of unseen messages {messages.Count}");
}
}
}
}
First you need an IMAP client; this is the client you get from the library:
Next, open access to your inbox folder:
Finally, get the list of messages with the flag "Not seen" and after return the count of values: