Delphi DLL
Delphi DLL
List IMAP Mailboxes
List the mailboxes available within an IMAP account.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Imap, Mailboxes;
...
procedure TForm1.Button1Click(Sender: TObject);
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,'MY-IMAP-DOMAIN');
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
// Login
success := CkImap_Login(imap,'MY-IMAP-LOGIN','MY-IMAP-PASSWORD');
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
refName := '';
// refName is usually set to an empty string.
// A non-empty reference name argument is the name of a mailbox or a level of
// mailbox hierarchy, and indicates the context in which the mailbox
// name is interpreted.
// Select all mailboxes matching this pattern:
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.oldSupport
// INBOX.vendors.paypal
// INBOX.sales
// INBOX.lists
// INBOX.Drafts
// INBOX.vendors.dell
// INBOX.Trash
// INBOX.invoiceRequests
// INBOX.purchases
// INBOX.vendors.inMotion
// INBOX.oldEmail
// INBOX.vendors
// INBOX.lists.python
// INBOX.vendors.myhosting
// INBOX.Templates
// INBOX.friends
// INBOX.bounceSamples
// INBOX.lists.ruby
// INBOX.vendors.peer1
// INBOX.Sent
// INBOX.Junk
// INBOX
// Disconnect from the IMAP server.
success := CkImap_Disconnect(imap);
CkImap_Dispose(imap);
CkMailboxes_Dispose(mboxes);
end;