ComponentPro UltimateMail

      Purging messages

      Language Filter: AllSend comments on this topic to ComponentPro

      To purge all messages marked as deleted from the current folder, you can either call Purge or Deselect(true) methods.

      The following steps will help you to do that:

      Purging all messages marked as deleted

      1. Add using directives to your code to create aliases for existing namespaces and avoid having to type the fully qualified type names. The code looks similar to the following:
        using ComponentPro.Net;
        using ComponentPro.Net.Mail;
        
      2. Create a new instance of the Imap class.
      3. Now you can connect to the IMAP server with Connect methods. The code looks similar to the following:
        // IMAP server information. 
        const string serverName = "myserver";
        const string user = "name@domain.com";
        const string password = "mytestpassword";
        const int port = 993;
        const SslSecurityMode securityMode = SslSecurityMode.Implicit;
        
        // Create a new instance of the Imap class.
        Imap client = new Imap();
        
        // Connect to the server.
        client.Connect(serverName, port, securityMode);
        
      4. Use your user name and password to login with Authenticate methods.  The code looks similar to the following:
        // Login to the server.
        client.Authenticate(user, password);
        
      5. Now select a mailbox and delete one or more messages, and then call the Purge method. The code looks similar to the following:
        // Select 'INBOX' mailbox
        client.Select("INBOX");
        
        // Delete a message with Sequence number # 1.
        client.DeleteMessage(1);
        
        // ... 
         
        // Purge all messages marked as deleted in the 'INBOX' mailbox
        client.Purge();
        
      6. After completing your work, call the Disconnect method to close the IMAP session. 

      Final example code

      using ComponentPro.Net;
      using ComponentPro.Net.Mail;
      
      ...
      
      // IMAP server information. 
      const string serverName = "myserver";
      const string user = "name@domain.com";
      const string password = "mytestpassword";
      const int port = 993;
      const SslSecurityMode securityMode = SslSecurityMode.Implicit;
      
      // Create a new instance of the Imap class.
      Imap client = new Imap();
      
      // Connect to the server.
      client.Connect(serverName, port, securityMode);
      
      // Login to the server.
      client.Authenticate(user, password);
      
      // Select 'INBOX' mailbox
      client.Select("INBOX");
      
      // Delete a message with Sequence number # 1.
      client.DeleteMessage(1);
      
      // ... 
       
      // Purge all messages marked as deleted in the 'INBOX' mailbox
      client.Purge();
      
      // Close the connection.
      client.Disconnect();