Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve IMAP Subfolders

Tags:

c#

mailkit

I am trying to retrieve the subfolders and messages from the inbox but i was only able to retrieve the parent subfolders, also tried with PersonalNamespaces[0]

var inbox = client.Inbox;
inbox.Open (FolderAccess.ReadWrite);

Debug.WriteLine ("Total messages: {0}", inbox.Count);
//client.Inbox.Status(StatusItems.Unread);
//Debug.WriteLine("Recent messages: {0}", inbox.Unread);
//Debug.WriteLine("Recent messages: {0}", inbox.FirstUnread);

var personal = client.GetFolder(client.PersonalNamespaces[0]);

foreach (var folder in inbox.GetSubfolders(false))
{
        Console.WriteLine("[folder] {0}", folder.Name);
        folder.Open(FolderAccess.ReadOnly);
like image 372
user3430435 Avatar asked Sep 27 '22 20:09

user3430435


1 Answers

Not all IMAP servers will even allow subfolders of the INBOX folder. If you are sure that your IMAP account's INBOX folder has subfolders, you would use the following code snippet to get them:

foreach (var folder in client.Inbox.GetSubfolders (false)) {
    Console.WriteLine ("[folder] {0}", folder.Name);
}
like image 167
jstedfast Avatar answered Oct 07 '22 18:10

jstedfast