Reputation: 31
How read last unread message from mail box and after mark this message "Unseen"
I use s22.imap.dll
ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_Username",
"My_Password", true, AuthMethod.Login);
// Get a list of unique identifiers (UIDs) of all unread messages in the mailbox.
uint[] uids = Client.Search( SearchCondition.Unseen() );
// Fetch the messages and print out their subject lines.
foreach(uint uid in uids) {
MailMessage message = Client.GetMessage(uid);
Console.WriteLine(message.Subject);
}
// Free up any resources associated with this instance.
Client.Dispose();
Upvotes: 3
Views: 4955
Reputation: 51
First get uid last unread message:
var lastUid = Client.Search( SearchCondition.Unseen().Last() );
and read this message;
MailMessage message = Client.GetMessage( lastUid );
To mark this message as "Unseen":
Client.RemoveMessageFlags( lastUid, null, MessageFlag.Seen );
See more on: ImapClient.RemoveMessageFlags Method
Upvotes: 5