Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Load Emails from a .mbx Mailbox File
See more POP3 Examples
Demonstrates the Chilkat MailMan.LoadMbxFile method, which loads emails from a .mbx mailbox file and stores them in an EmailBundle. If a filter has been configured, only the matching emails are returned. This example loads a local mailbox file and iterates the resulting bundle.
Background: An
.mbx file is a single-file mailbox format that stores many messages concatenated together — historically produced by Outlook Express and similar clients. LoadMbxFile parses that archive into individual Email objects, which is useful for importing, migrating, or analyzing old mail without any server connection. No POP3 or SMTP session is involved — this reads purely from disk.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.MailMan,
Chilkat.EmailBundle,
Chilkat.Email;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mailman: TMailMan;
bundle: TEmailBundle;
n: Integer;
email: TEmail;
i: Integer;
begin
success := False;
// Demonstrates the MailMan.LoadMbxFile method, which loads emails from a .mbx mailbox file
// and stores them in an EmailBundle. If a filter has been configured, only the matching
// emails are returned.
mailman := TMailMan.Create;
// Load emails from a local .mbx mailbox file (no server connection is made).
bundle := TEmailBundle.Create;
success := mailman.LoadMbxFile('qa_data/mbx/inbox.mbx',bundle);
if (success = False) then
begin
WriteLn(mailman.LastErrorText);
Exit;
end;
n := bundle.MessageCount;
WriteLn('Loaded ' + n + ' emails from the .mbx file.');
email := TEmail.Create;
for i := 0 to n - 1 do
begin
success := bundle.EmailAt(i,email);
WriteLn(email.Subject);
end;
// Note: The path "qa_data/mbx/inbox.mbx" is a relative local filesystem path,
// relative to the current working directory of the running application.
mailman.Free;
bundle.Free;
email.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.