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

MIME Multipart Boundary and Preamble Properties

See more MIME Examples

Demonstrates the Boundary property, which gets or sets the raw boundary token of a multipart entity (without surrounding quotation marks), and UseMmDescription, which controls whether the conventional preamble text is emitted when serializing a multipart entity.

Background. A multipart boundary separates the constituent parts. Chilkat quotes the token automatically in the header when required. The preamble is ignored by MIME-aware readers and is off by default.

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;
  part: TMime;
  mimeStr: string;

begin
  success := False;

  mime := TMime.Create;

  //  Create a multipart/mixed entity.
  success := mime.NewMultipartMixed();
  if (success = False) then
    begin
      WriteLn(mime.LastErrorText);
      Exit;
    end;

  //  Boundary is the raw boundary token, without surrounding quotation marks.  Chilkat quotes it
  //  automatically in the serialized header when required.
  mime.Boundary := 'example-boundary';

  //  UseMmDescription controls whether the conventional preamble text
  //  "This is a multi-part message in MIME format." is emitted.  The default is False.
  mime.UseMmDescription := True;

  //  Add a simple part so the multipart has content.
  part := TMime.Create;
  success := part.SetBodyFromPlainText('First part.');
  if (success = False) then
    begin
      WriteLn(part.LastErrorText);
      Exit;
    end;
  success := mime.AppendPart(part);
  if (success = False) then
    begin
      WriteLn(mime.LastErrorText);
      Exit;
    end;

  WriteLn('Boundary = ' + mime.Boundary);

  mimeStr := mime.GetMime();
  if (mime.LastMethodSuccess = False) then
    begin
      WriteLn(mime.LastErrorText);
      Exit;
    end;
  WriteLn(mimeStr);


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