ImapCreateFolder Method |
Namespace: MailBee.ImapMail
Exception | Condition |
---|---|
MailBeeException | An error occurred and ThrowExceptions is true. |
The developer should specify the full name of the folder (including all parent folders' names if the new folder should be a subfolder of another existing folder). For instance, imap.CreateFolder("Orders") call will create "Orders" folder, not "Inbox/Orders" even if "Inbox" folder is currently selected.
This method automatically creates parent folders if required. For instance, if folderName is "Archive/April/29" and there is no "Archive" folder in the account, this method will create "Archive", "Archive/April", and "Archive/April/29" folders.
Note |
---|
Although the most popular delimiter char for separating folder levels is "/", some IMAP4 servers may use "\", ".", etc, or even do not support folder hierarchy at all (flat names). The developer can obtain the folder delimiter char adopted by the current server using DownloadFolders(Boolean, String, String) method. |
Note |
---|
Depending on the mail server implementation, folder names other than "Inbox" may be case-sensitive ("Drafts", "DRAFTS", and "drafts" may designate different folder names). |
MailBee fully supports international folder names encoded with UTF-7 Modified encoding.
To create a folder asynchronously, see the sample code in BeginExecuteCustomCommand(String, String, AsyncCallback, Object) topic.
// To use the code below, import MailBee namespaces at the top of your code using MailBee; using MailBee.ImapMail; // The actual code (put it into a method of your class) Imap imp = new Imap(); // Connect to the server and log in the account. imp.Connect("imap4.company.com"); imp.Login("jdoe@company.com", "secret"); // Determine what delimiter char is on the server. FolderCollection delim = imp.DownloadFolders(false, string.Empty, string.Empty); string folderName = null; if (delim.Count == 0) { Console.WriteLine("Bad IMAP4 server"); } else if (delim[0].Delimiter == null) { folderName = "Inbox/Orders"; Console.WriteLine("Folder names are flat. Will create " + folderName + " folder."); } else { folderName = "Inbox" + delim[0].Delimiter + "Orders"; Console.WriteLine("Will create " + folderName + " folder."); } // Create folder imp.CreateFolder(folderName); Console.WriteLine(folderName + " folder successfully created."); imp.Disconnect();