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

Create an email with plain-text and HTML bodies

See more Email Object Examples

Set the From and Reply-To addresses, add a recipient, and provide plain-text and HTML versions of the same body. Save the message as text-and-html.eml.

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;

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

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

begin
  success := False;

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

  email := TEmail.Create;
  email.FromName := 'Sam Lee';
  email.FromAddress := 'sam@example.com';
  email.ReplyTo := 'replies@example.com';
  success := email.AddTo('Alex Rivera','alex@example.net');
  if (success <> True) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;
  email.Subject := 'Sample message';
  email.Charset := 'utf-8';
  //  A custom header can carry a reference alongside the standard message fields.
  email.AddHeaderField('X-Reference-ID','REF-42');
  success := email.AddPlainTextAlternativeBody('Read more at https://example.com/details.');
  if (success <> True) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;
  success := email.AddHtmlAlternativeBody('<p><a href=''https://example.com/details''>Read more</a></p>');
  if (success <> True) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;

  success := email.SaveEml('text-and-html.eml');
  if (success <> True) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;
  WriteLn('Saved text-and-html.eml.');


  email.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.