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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With