user1266870
user1266870

Reputation: 31

How to mark unseen last unread message S22.imap

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

Answers (1)

colaus
colaus

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

Related Questions