6

我的代码是:

 using (ImapClient client = new ImapClient())
 {
     // Connect to the server and authentication and then 
     var inbox = client.Inbox;
     inbox.Open(FolderAccess.ReadOnly);
     int messageCount = inbox.Count - 1;
     for (int i = messageCount; i > 0 ; i--)
     {
           var visitor = new HtmlPreviewVisitor();
           MimeMessage message = inbox.GetMessage(i);
           message.Accept(visitor);
           // how can get uid for this message
     }
 }

我想保存 uid 。如何获取消息的uid?

MimeMessage message =inbox.GetMessage(UniqueId.Parse(uid));
4

1 回答 1

15

使用 MailKit 获取特定消息的 UID 的Fetch()方法是使用实​​例上的方法并将枚举值ImapFolder传递给它。MessageSummaryItem.UniqueId

通常,您需要在获取实际消息之前获取文件夹中消息的 UID ,如下所示:

// fetch some useful metadata about each message in the folder...
var items = folder.Fetch (0, -1, MessageSummaryItems.UniqueId | MessageSummaryItems.Size | MessageSummaryItems.Flags);

// iterate over all of the messages and fetch them by UID
foreach (var item in items) {
    var message = folder.GetMessage (item.UniqueId);

    Console.WriteLine ("The message is {0} bytes long", item.Size.Value);
    Console.WriteLine ("The message has the following flags set: {0}", item.Flags.Value);
}

Flags包括诸如SeenDeletedAnswered等之类的内容。Flagged标志表示该消息已被用户标记为“重要”。

于 2016-05-02T15:38:21.553 回答