Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MailKit Imap Get only messageId

Tags:

c#

mailkit

The title sums it up. I need to get all the MessageId properties from an Imap folder without downloading the entire message.

...
IMailFolder inbox = imapClient.Inbox;
SearchQuery query = SearchQuery.All;

IList<UniqueId> idsList = inbox.Search(query);

foreach (var uid in idsList)
{
  MimeMessage message = inbox.GetMessage(uid);//This gets the entire message
    //but I only need the .MessageId, without getting the other parts
    if (message != null)
    {
       string messageId = message.MessageId;
    }
}
...
like image 429
Martin Ralovski Avatar asked Apr 14 '15 16:04

Martin Ralovski


1 Answers

Try this instead:

var summaries = client.Inbox.Fetch (0, -1, MessageSummaryItems.Envelope);
foreach (var message in summaries) {
    Console.WriteLine (message.Envelope.MessageId);
}

That should get you what you want.

like image 142
jstedfast Avatar answered Oct 09 '22 02:10

jstedfast