ComponentPro UltimateMail

      Obtaining mailbox information Synchronously

      Language Filter: AllSend comments on this topic to ComponentPro

      The simplest way to obtain information about a specified mailbox is using GetMailboxStat method. The method returns a Pop3MailboxStat object containing information about the mailbox you have requested.

      The following steps will help you to do that:

      Getting Mailbox Stat

      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 System;
        using ComponentPro.Net.Mail;
        
      2. Create a new instance of the Pop3 class.
      3. Now you can connect to the POP3 server with Connect methods. The code looks similar to the following:
        // Create a new instance of the Pop3 class.
        Pop3 client = new Pop3();
        
        // Connect to the server.
        client.Connect("myserver");
        
        // Or you can specify the POP3 port with 
        // client.Connect("myserver", 110);
        
      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 pass the mailbox name to the GetMailboxStat method. The code looks similar to the following:
        // Obtain mailbox information.
        Pop3MailboxStat info = client.GetMailboxStat();
        
        // Print out some information.
        Console.WriteLine("Number of messages found: {0}", info.MessageCount);
        Console.WriteLine("Mailbox Size: {0}", info.Size);
        
      6. After completing your work, call the Disconnect method to close the POP3 session.

      Final example code

      using System;
      using ComponentPro.Net.Mail;
      
      ...
      
      // Create a new instance of the Pop3 class.
      Pop3 client = new Pop3();
      
      // Connect to the server.
      client.Connect("myserver");
      
      // Or you can specify the POP3 port with 
      // client.Connect("myserver", 110); 
       
      // Login to the server.
      client.Authenticate("user", "password");
      
      // Obtain mailbox information.
      Pop3MailboxStat info = client.GetMailboxStat();
      
      // Print out some information.
      Console.WriteLine("Number of messages found: {0}", info.MessageCount);
      Console.WriteLine("Mailbox Size: {0}", info.Size);
      
      // Close the connection.
      client.Disconnect();