Sample code for 30+ languages & platforms
C#

List Email UIDs

List the UIDs of each email in a mailbox.

Chilkat C# Downloads

C#
bool success = false;

Chilkat.Imap imap = new Chilkat.Imap();

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

//  Connect to an IMAP server.
//  Use TLS
imap.Ssl = true;
imap.Port = 993;
success = imap.Connect("MY-IMAP-DOMAIN");
if (success == false) {
    Debug.WriteLine(imap.LastErrorText);
    return;
}

//  Login
success = imap.Login("MY-IMAP-LOGIN","MY-IMAP-PASSWORD");
if (success == false) {
    Debug.WriteLine(imap.LastErrorText);
    return;
}

//  Select an IMAP mailbox
success = imap.SelectMailbox("Inbox");
if (success == false) {
    Debug.WriteLine(imap.LastErrorText);
    return;
}

//  Get the message IDs of all the emails in the mailbox
//  We can choose to fetch UIDs or sequence numbers.
bool fetchUids = true;
Chilkat.MessageSet messageSet = new Chilkat.MessageSet();
success = imap.QueryMbx("ALL",fetchUids,messageSet);
if (success == false) {
    Debug.WriteLine(imap.LastErrorText);
    return;
}

int i = 0;
int n = messageSet.Count;
while (i < n) {
    Debug.WriteLine(Convert.ToString(messageSet.GetId(i)));
    i = i + 1;
}

//  Disconnect from the IMAP server.
success = imap.Disconnect();