Sample code for 30+ languages & platforms
Lazarus Pascal Requires Chilkat v11.0.0+

Inspect the MIME structure and contents of an EML file

See more Email Object Examples

Open the complete EML in Mime for a tree view and in Email for application-level collections. An HTML logo, downloadable file, attached message, and delivery report are counted separately. Try the complex workshop draft.

Chilkat Lazarus Pascal Downloads

Lazarus Pascal
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.Email,
  Chilkat.Mime;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  email: TEmail;
  mime: TMime;
  i: Integer;

begin
  success := False;

  //  Assumes Chilkat is unlocked. See Global Unlock Sample.

  email := TEmail.Create;
  success := email.LoadEml('workshop.eml');
  if (success <> True) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;
  mime := TMime.Create;
  success := mime.LoadMimeFile('workshop.eml');
  if (success <> True) then
    begin
      WriteLn(mime.LastErrorText);
      Exit;
    end;
  WriteLn(mime.GetStructure('text'));
  WriteLn('Subject: ' + email.Subject);
  WriteLn('Files: ' + email.NumAttachments + '  Related items: ' + email.NumRelatedItems);
  WriteLn('Attached messages: ' + email.NumAttachedMessages + '  Reports: ' + email.NumReports);
  i := 0;
  while (i < email.NumAttachments) do
    begin
      WriteLn(email.GetAttachmentFilename(i) + '  ' + email.GetAttachmentContentType(i) + '  ' + email.GetAttachmentSize(i) + ' bytes');
      i := i + 1;
    end;

  i := 0;
  while (i < email.NumRelatedItems) do
    begin
      WriteLn('Related: ' + email.GetRelatedFilename(i) + '  ' + email.GetRelatedContentType(i));
      i := i + 1;
    end;



  email.Free;
  mime.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.