Connect IMAP
Connects to an IMAP server and selects a mailbox.
Code
using DRIT.Mail.Rfc.Imap;
var options = new ImapClientOptions
{
Host = "imap.example.com",
Port = 993,
SslMode = ImapSslMode.Ssl,
Credentials = new System.Net.NetworkCredential("user", "password"),
};
using var client = new ImapClient(options);
client.Connect();
client.Authenticate();
// List available mailboxes
foreach (ImapMailbox mailbox in client.ListMailboxes())
{
Console.WriteLine($"{mailbox.Flags}: {mailbox.Name}");
}
// Select the INBOX
ImapMailboxStatus inbox = client.SelectMailbox("INBOX");
Console.WriteLine($"Messages: {inbox.MessageCount}");
Console.WriteLine($"Unseen: {inbox.UnseenCount}");
client.Disconnect();
Remarks
ImapClient implements RFC 9051 (IMAP4rev2). Mailbox names use the
server's hierarchy delimiter (commonly / or .).