Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Load MIME from a String

See more MIME Examples

Demonstrates the Chilkat Mime.LoadMime method, which parses complete MIME text and replaces the current object's headers, body, and multipart tree. The only argument is the MIME string.

Background: MIME is the structure behind email messages and many other content containers — a set of headers, a blank line, then a body that may itself be a tree of nested parts. Loading parses that text into an object you can then inspect and modify part by part. A successful load fully replaces whatever the object held before, and Chilkat is tolerant of common real-world formatting quirks. When the content may contain raw 8-bit or NUL bytes, prefer LoadMimeBd so nothing is forced through a text string.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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.Mime;

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

procedure RunDemo;
var
  success: Boolean;
  mime: TMime;
  mimeText: string;

begin
  success := False;

  //  Demonstrates the Mime.LoadMime method, which parses complete MIME text and replaces the current
  //  object's headers, body, and multipart tree.  The only argument is the MIME string.

  mime := TMime.Create;

  //  The complete MIME text (headers, a blank line, then the body).
  mimeText := 'Content-Type: text/plain' + #13#10 + #13#10 + 'This is the body.' + #13#10;

  success := mime.LoadMime(mimeText);
  if (success = False) then
    begin
      WriteLn(mime.LastErrorText);
      Exit;
    end;

  WriteLn('Content-Type: ' + mime.ContentType);


  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.