• DR-IT Software
  • Products
  • Documentation
  • Product page
  • Examples
  • API reference
  • Support
Show / Hide Table of Contents

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 .).

  • Improve this Doc
Back to top

DR-IT Software documentation

DR-IT Software · Products · Documentation index · Product page · Downloads · Support · Licensing

Generated by DocFX