using(var client = new ImapClient()) { client.Connect("imap.example.com", 993, true); client.Authenticate("username", "password"); client.Inbox.Open(FolderAccess.ReadOnly); var uids = client.Inbox.Search(SearchQuery.All); foreach (var uid in uids) { var message = client.Inbox.GetMessage(uid); Console.WriteLine(message.Subject); } client.Disconnect(true); }
using(var client = new ImapClient()) { client.Connect("imap.example.com", 993, true); client.Authenticate("username", "password"); client.Inbox.Open(FolderAccess.ReadWrite); var uids = client.Inbox.Search(SearchQuery.All); foreach (var uid in uids) { client.Inbox.AddFlags(uid, MessageFlags.Deleted, true); } client.Inbox.Expunge(); client.Disconnect(true); }This code connects to an IMAP server, authenticates the user, opens the inbox folder and marks all messages as deleted. It then permanently deletes the messages from the server. In summary, ImapCommand is a key class in the MailKit.Net.Imap package library that enables easy manipulation of email messages on an IMAP server. The library provides useful methods for connecting to a server, authenticating, and performing various actions such as retrieving and deleting messages.