I am using MailKit to read messages from a gmail account. Works great. But, I want to get the message status as whether its read, unread, important, starred etc. Is this possible with MailKit? I can´t seem to find anything about it.
Here is my code:
var inbox = client.Inbox;
var message = inbox.GetMessage(4442);//4442 is the index of a message.
Console.WriteLine("Message Importance : {0}", message.Importance);
Console.WriteLine("Message Priority : {0}", message.Priority);
Importance and priority always returns "Normal". How to find this message is marked as important or not? and how to get read or unread status of this message?.
There is no message property because a MimeMessage is just the parsed raw MIME message stream and IMAP does not store those states on the message stream, it stores them separately.
To get the info you want, you'll need to use the Fetch()
method:
var info = client.Inbox.Fetch (new [] { 4442 }, MessageSummaryItems.Flags | MessageSummaryItems.GMailLabels);
if (info[0].Flags.Value.HasFlag (MessageFlags.Flagged)) {
// this message is starred
}
if (info[0].Flags.Value.HasFlag (MessageFlags.Draft)) {
// this is a draft
}
if (info[0].GMailLabels.Contains ("Important")) {
// the message is Important
}
Hope that helps.
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