简体   繁体   中英

how to get uid in mailkit?

my code is:

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

I wand to save uid . how can get uid for message ?

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

The way to get the UID for a particular message using MailKit is to use the Fetch() method on the ImapFolder instance and pass it the MessageSummaryItem.UniqueId enum value.

Typically you'll want to get the UIDs of the messages in the folder before you fetch the actual message(s), like so:

// 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);
}

The Flags includes things like Seen , Deleted , Answered , etc. The Flagged flag means that the message has been flagged as "important" by the user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM