Following code snippets demonstrate how to create, rename and delete a folder on mail server by using ImapClient class in Spire.Email.
Create a mail folder
using Spire.Email;
using Spire.Email.IMap;
using System;
namespace CreateMailFolder
{
class Program
{
static void Main(string[] args)
{
//create an imapclient with username, password and host
ImapClient client = new ImapClient();
client.Username = "test@outlook.com";
client.Password = "password";
client.Host = "outlook.office365.com";
//specify the port
client.Port = 143;
//specify the connection protocol
client.ConnectionProtocols = ConnectionProtocols.Ssl;
//connect to imap mail server
client.Connect();
//create a folder named ‘e-iceblue’
client.CreateFolder("e-iceblue");
Console.WriteLine("Done!");
}
}
}

Rename a mail folder
using Spire.Email;
using Spire.Email.IMap;
using System;
namespace RenameMailFolder
{
class Program
{
static void Main(string[] args)
{
//create an imapclient with username, password and host
ImapClient client = new ImapClient();
client.Username = "test@outlook.com";
client.Password = "password";
client.Host = "outlook.office365.com";
//specify the port
client.Port = 143;
//specify the connection protocol
client.ConnectionProtocols = ConnectionProtocols.Ssl;
//connect to imap mail server
client.Connect();
//rename an existing folder with a new name
client.RenameFolder("e-iceblue", "E-ICEBLUE");
Console.WriteLine("Done!");
}
}

Delete a mail folder
using Spire.Email;
using Spire.Email.IMap;
using System;
namespace DeleteMailFolder
{
class Program
{
static void Main(string[] args)
{
//create an imapclient with username, password and host
ImapClient client = new ImapClient();
client.Username = "test@outlook.com";
client.Password = "password";
client.Host = "outlook.office365.com";
//specify the port
client.Port = 143;
//specify the connection protocol
client.ConnectionProtocols = ConnectionProtocols.Ssl;
//connect to imap mail server
client.Connect();
//delete an existing folder
client.DeleteFolder("E-ICEBLUE");
Console.WriteLine("Done!");
}
}
}

