Sample code for 30+ languages & platforms
Delphi DLL Requires Chilkat v11.0.0+

List IMAP Mailboxes with Reference

Demonstrates how to list all sub-mailboxes within a specified context. In this case, we list all mailboxes under "INBOX.vendors".

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
imap: HCkImap;
refName: PWideChar;
wildcardedMailbox: PWideChar;
subscribed: Boolean;
mboxes: HCkMailboxes;
i: Integer;

begin
success := False;

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

imap := CkImap_Create();

//  Connect to an IMAP server.
//  Use TLS
CkImap_putSsl(imap,True);
CkImap_putPort(imap,993);
success := CkImap_Connect(imap,'imap.example.com');
if (success = False) then
  begin
    Memo1.Lines.Add(CkImap__lastErrorText(imap));
    Exit;
  end;

//  Login
success := CkImap_Login(imap,'admin@chilkatsoft.com','myPassword');
if (success = False) then
  begin
    Memo1.Lines.Add(CkImap__lastErrorText(imap));
    Exit;
  end;

//  Get the list of mailboxes.
refName := '';
wildcardedMailbox := '*';
subscribed := False;

mboxes := CkMailboxes_Create();
success := CkImap_MbxList(imap,subscribed,refName,wildcardedMailbox,mboxes);
if (success = False) then
  begin
    Memo1.Lines.Add(CkImap__lastErrorText(imap));
    Exit;
  end;

i := 0;
while i < CkMailboxes_getCount(mboxes) do
  begin
    Memo1.Lines.Add(CkMailboxes__getName(mboxes,i));
    i := i + 1;
  end;

//  Sample output looks like this:
//  INBOX.vendors.shareit
//  INBOX.vendors.paypal
//  INBOX.vendors.dell
//  INBOX.vendors.inMotion
//  INBOX.vendors.myhosting
//  INBOX.vendors.peer1

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

CkImap_Dispose(imap);
CkMailboxes_Dispose(mboxes);