Deleting a Message

The following example demonstrates how to mark a message for deletion, and then purge it from the IMAP server.

[C#]

IMAP4 imap = new IMAP4( "127.0.0.1", "dave@blah.com", "test" );
 
//set some logging properties
imap.Logger = new IMAPLog();
imap.Logger.Overwrite = true;
imap.Logger.Path = "c:\\imap.log";
 
//login
imap.Login();
 
MailFolder inbox = imap.SelectInbox();
MessageClient mc = inbox.MessageClient;
FetchClient fc = inbox.FetchClient;
 
//download the first message
string contents = fc.MessageAsText(1);
 
//do something with the message 
Console.WriteLine( contents );
 
//decide we want to delete it
mc.Delete(1, IndexType.Ordinal);
 
//remove the deleted message(s)
mc.PurgeDeletedMessages();
 
imap.Disconnect();
 
Console.WriteLine( "Done" );
Console.ReadLine();

 

[VB.NET]

 Dim imap As New IMAP4("127.0.0.1", "dave@blah.com", "test")
  
 'set some logging properties
 imap.Logger = New IMAPLog()
 imap.Logger.Overwrite = True
 imap.Logger.Path = "c:\imap.log"
  
 'login
 imap.Login()
  
 Dim inbox As MailFolder = imap.SelectInbox()
 Dim mc As MessageClient = inbox.MessageClient
 Dim fc As FetchClient = inbox.FetchClient
  
 'download the first message
 Dim contents As String = fc.MessageAsText(1)
  
 'do something with the message 
 Console.WriteLine(contents)
  
 'decide we want to delete it
 mc.Delete(1, IndexType.Ordinal)
  
 'remove the deleted message(s)
 mc.PurgeDeletedMessages()
  
 imap.Disconnect()
  
 Console.WriteLine("Done")
 Console.ReadLine()