How to List Messages
Both ImapClient and Pop3Client allow you to retrieve a list of messages on the server with methods named ListMessages.With the Pop3Client, you can pass an optional flag parameter indicating which part of the message will be retrieved. The ListMessages method returns a collection of Pop3Message object containing information about messages you have requested as shown the following steps:
C# using ComponentSoft.Net.Mail; VB.NET Imports ComponentSoft.Net.Mail // Create a new instance of the Pop3Client class. VB.NET ' Create a new instance of the Pop3Client class.
C#
Pop3Client client = new Pop3Client();
// 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");
// List messages. Only Size and UniqueId are retrieved.
Pop3MessageCollection list = client.ListMessages(EnvelopeParts.Size | EnvelopeParts.UniqueId);
foreach (Pop3Message m in list)
{
Console.WriteLine(string.Format("UniqueId: {0}, Size: {1}", m.UniqueId, m.Size));
}
// Close the connection.
client.Disconnect();
Dim client As New Pop3Client()
' 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")
' List messages. Only Size and UniqueId are retrieved.
Dim list As Pop3MessageCollection = client.ListMessages(EnvelopeParts.Size OrEnvelopeParts.UniqueId)
For Each m As Pop3Message In list
Console.WriteLine(String.Format("UniqueId: {0}, Size: {1}", m.UniqueId, m.Size))
Next m
' Close the connection.
client.Disconnect()