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

Set the Email Body from a BinData

See more Email Object Examples

Demonstrates the Chilkat Email.SetBodyBd method, which sets the main email body from the binary data in a BinData object. The second argument is the MIME Content-Type, the third is the disposition (may be empty, inline, or attachment), and the fourth is the filename. This example loads HTML content into a BinData and sets it as the body.

Background: SetBodyBd gives low-level control over the body when you already have its bytes and want to specify the exact Content-Type and MIME disposition yourself. It suits content that is generated or stored as binary — for example an EDI payload, a pre-rendered HTML fragment, or any custom content type — where the convenience of SetHtmlBody / SetTextBody does not apply.

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.Email,
  Chilkat.BinData;

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

procedure RunDemo;
var
  success: Boolean;
  email: TEmail;
  bd: TBinData;

begin
  success := False;

  //  Demonstrates the SetBodyBd method, which sets the main email body from the binary data in
  //  a BinData object.  The second argument is the MIME Content-Type, the third is the
  //  disposition (may be empty, "inline", or "attachment"), and the fourth is the filename.

  email := TEmail.Create;
  email.Subject := 'Body from BinData';

  //  Load the body content from a file into a BinData object.
  bd := TBinData.Create;
  success := bd.LoadFile('qa_data/html/body.html');
  if (success = False) then
    begin
      WriteLn(bd.LastErrorText);
      Exit;
    end;

  //  Set the main body from the binary data as text/html.
  success := email.SetBodyBd(bd,'text/html','','');
  if (success = False) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;

  WriteLn('HasHtmlBody: ' + email.HasHtmlBody());

  //  Note: The path "qa_data/html/body.html" is a relative local filesystem path,
  //  relative to the current working directory of the running application.


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