ImapClient imap = new ImapClient();
imap.Host = "outlook.office365.com";
imap.Port = 143;
imap.Username = "x@y";
imap.Password = "password";
imap.ConnectionProtocols = ConnectionProtocols.Ssl;
imap.Connect();
imap.Select("inbox");
//Find all read messages
ImapMessageCollection imapMessage = imap.Search("'Seen' = 'true'");
foreach (ImapMessage message1 in imapMessage)
{
//Copy mail to archive folder
imap.Copy(message1.SequenceNumber, "archive");
//Mark the message as deleted
imap.MarkAsDeleted(message1.SequenceNumber);
}
//Delete all flagged messages
imap.DeleteMarkedMessages();