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
- 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;
Imports ComponentPro.Net.Mail
- Create a new instance of the Pop3 class.
- 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);
' Create a new instance of the Pop3 class.
Dim client As New Pop3()
' Connect to the server.
client.Connect("myserver")
' Or you can specify the POP3 port with
' client.Connect("myserver", 110);
- 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");
' Login to the server.
client.Authenticate("user", "password")
- 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);
' Obtain mailbox information.
Dim info As Pop3MailboxStat = client.GetMailboxStat()
' Print out some information.
Console.WriteLine("Number of messages found: {0}", info.MessageCount)
Console.WriteLine("Mailbox Size: {0}", info.Size)
- 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();
Imports ComponentPro.Net.Mail
...
' Create a new instance of the Pop3 class.
Dim client As 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.
Dim info As Pop3MailboxStat = 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()