MailKit Imap只获取messageId

时间:2015-04-14 16:28:25

标签: c# mailkit

标题总结了它。我需要从Imap文件夹中获取所有MessageId属性,而不下载整个消息。

...
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;
    }
}
...

1 个答案:

答案 0 :(得分:7)

请改为尝试:

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

那应该能得到你想要的东西。