public static void Run()
{
// 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
{
// The root folder (which will be created on disk) consists of host and username
string rootFolder = client.Host + "-" + client.Username;
// Create the root folder and List all the folders from IMAP server
Directory.CreateDirectory(rootFolder);
ImapFolderInfoCollection folderInfoCollection = client.ListFolders();
foreach (ImapFolderInfo folderInfo in folderInfoCollection)
{
// Call the recursive method to read messages and get sub-folders
ListMessagesInFolder(folderInfo, rootFolder, client);
}
// Disconnect to the remote IMAP server
client.Dispose();
}
catch (Exception ex)
{
Console.Write(Environment.NewLine + ex);
}
Console.WriteLine(Environment.NewLine + "Downloaded messages recursively from IMAP server.");
}