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

Create a multipart/mixed MIME Entity

See more MIME Examples

Demonstrates the Chilkat Mime.NewMultipartMixed method, which initializes the object as an empty multipart/mixed entity, clearing any existing content. It takes no arguments; child parts are then appended.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: multipart/mixed is the container for independent parts shown one after another — the classic "message body plus attachments" layout. Each child is its own distinct content, unlike multipart/alternative (competing renderings of the same thing) or multipart/related (a part and its embedded resources). Start here, then AppendPart a body and AppendPartFromFile the attachments.

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;
  bodyPart: TMime;

begin
  success := False;

  //  Demonstrates the Mime.NewMultipartMixed method, which initializes the object as an empty
  //  multipart/mixed entity, clearing any existing headers, body, and child parts.  It takes no
  //  arguments.

  mime := TMime.Create;

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

  //  Append child parts.  multipart/mixed is the container for a message body plus attachments.
  bodyPart := TMime.Create;
  success := bodyPart.SetBodyFromPlainText('See the attached report.');
  if (success = False) then
    begin
      WriteLn(bodyPart.LastErrorText);
      Exit;
    end;
  success := mime.AppendPart(bodyPart);
  if (success = False) then
    begin
      WriteLn(mime.LastErrorText);
      Exit;
    end;

  success := mime.AppendPartFromFile('qa_data/report.pdf');
  if (success = False) then
    begin
      WriteLn(mime.LastErrorText);
      Exit;
    end;

  WriteLn('Number of parts: ' + mime.NumParts);


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