public static void Run()
{
// ExStart:ConnectingWithIMAPServer
// Create an instance of the ImapClient class
ImapClient client = new ImapClient();
// Specify host, username, password, Port and SecurityOptions for your client
client.Host = "imap.gmail.com";
client.Username = "[email protected]";
client.Password = "your.password";
client.Port = 993;
client.SecurityOptions = SecurityOptions.Auto;
try
{
// Get all folders in the currently subscribed folder
ImapFolderInfoCollection folderInfoColl = client.ListFolders();
// Iterate through the collection to get folder info one by one
foreach (ImapFolderInfo folderInfo in folderInfoColl)
{
// Folder name and get New messages in the folder
Console.WriteLine("Folder name is " + folderInfo.Name);
ImapFolderInfo folderExtInfo = client.GetFolderInfo(folderInfo.Name);
Console.WriteLine("New message count: " + folderExtInfo.NewMessageCount);
Console.WriteLine("Is it readonly? " + folderExtInfo.ReadOnly);
Console.WriteLine("Total number of messages " + folderExtInfo.TotalMessageCount);
}
// Disconnect to the remote IMAP server
client.Dispose();
}
catch (Exception ex)
{
Console.Write(Environment.NewLine + ex);
}
// ExEnd:ConnectingWithIMAPServer
Console.WriteLine(Environment.NewLine + "Getting folders information from IMAP server.");
}
}