Sample code for 30+ languages & platforms
Delphi DLL

Select an IMAP Mailbox

See more IMAP Examples

Demonstrates the Chilkat Imap.SelectMailbox method, which opens a mailbox for read-write access. A mailbox must be selected before message fetch, search, flag, copy, move, or expunge operations that act on messages. This example selects the Inbox.

Background: In IMAP, mail is organized into mailboxes (folders), and most message operations act on the currently selected one — so selecting a mailbox is the required step between logging in and working with messages. SelectMailbox opens it read-write, allowing changes such as setting flags or deleting. When you only need to read and must not alter anything (including the \Seen flag), use ExamineMailbox instead.

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
imap: HCkImap;

begin
success := False;

//  Demonstrates the Imap.SelectMailbox method, which opens a mailbox for read-write access.
//  A mailbox must be selected before message fetch, search, flag, copy, move, or expunge
//  operations that act on messages.

imap := CkImap_Create();

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;
success := CkImap_Login(imap,'user@example.com','myPassword');
if (success = False) then
  begin
    Memo1.Lines.Add(CkImap__lastErrorText(imap));
    Exit;
  end;

//  Open the Inbox for read-write access.
success := CkImap_SelectMailbox(imap,'Inbox');
if (success = False) then
  begin
    Memo1.Lines.Add(CkImap__lastErrorText(imap));
    Exit;
  end;

Memo1.Lines.Add('Inbox selected for read-write access.');

success := CkImap_Disconnect(imap);
if (success = False) then
  begin
    Memo1.Lines.Add(CkImap__lastErrorText(imap));
    Exit;
  end;

CkImap_Dispose(imap);