public static List<OpenPop.Mime.Message> FetchAllEmailMessages(string hostname, int port, bool useSsl, string username, string password)
{
// The client disconnects from the server when being disposed
using(Pop3Client client = new Pop3Client())
{
client.Connect(hostname, port, useSsl);
client.Authenticate(username, password);
// Get the number of messages in the inbox
int messageCount = client.GetMessageCount();
// We want to download all messages
List<OpenPop.Mime.Message> allMessages = new List<OpenPop.Mime.Message>(messageCount);
// Messages are numbered in the interval: [1, messageCount]
// Ergo: message numbers are 1-based.
for(int i = 1; i <= messageCount; i++)
allMessages.Add(client.GetMessage(i));
// Now return the fetched messages
return allMessages;
}
}