How to get the names of all mail folders using the MailKit library.

public ClientForm(ImapClient client, string email) { InitializeComponent(); treeViewFolder.HideSelection = false; panelFolders.Height = 0; _client = client; labelNameEmail.Text = email; client.GetFolders(/*Π’ΡƒΡ‚, ΠΊΠ°ΠΊ понимаю, Π½ΡƒΠΆΠ½ΠΎ ΠΊΠΎΠ½ΠΊΡ€Π΅Ρ‚Π½ΠΎ ΡƒΠΊΠ°Π·Ρ‹Π²Π°Ρ‚ΡŒ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΠΏΠ°ΠΏΠΊΠΈ, Π° ΠΌΠ½Π΅ Π½ΡƒΠΆΠ½ΠΎ ΡƒΠ·Π½Π°Ρ‚ΡŒ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ всСх ΠΏΠ°ΠΏΠΎΠΊ Π½Π΅ зная ΠΈΡ… названия*/) //client.Behavior.AutoPopulateFolderMessages = true; //CommonFolderCollection listFolders = client.Folders; //_key = new Dictionary<LinkLabel, TreeNode>(); //foreach (Folder folder in listFolders) //{ // TreeNode parentNode = treeViewFolder.Nodes.Add(folder.Name); // VisibleLinkLable(folder, parentNode); // if (folder.HasChildren) // { // AddTreeViewFolder(folder.SubFolders, parentNode); // } //} } 
  • The question will be more interesting if you add your code, even if it is still non-working. - 0xdb

1 answer 1

Very simple:

 IList<IMailFolder> folders = await client.GetFoldersAsync(client.PersonalNamespaces.First()); List<string> names = folders.Select(t => t.Name).ToList();