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

Choose the character set for an HTML email

See more Email Object Examples

Read a UTF-8 HTML file as Unicode, then set the charset Chilkat will use when writing the MIME text. The HTML file’s input encoding and the message’s output charset are separate choices. UTF-8 can represent names from multiple writing systems.

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

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

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

begin
  success := False;

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

  email := TEmail.Create;
  email.From := 'Workshop team <events@example.com>';
  success := email.AddTo('Alex Rivera','alex@example.net');
  if (success <> True) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;
  email.Subject := 'Workshop registration';
  html := TStringBuilder.Create;
  success := html.LoadFile('newsletter.html','utf-8');
  if (success <> True) then
    begin
      WriteLn('Failed: html.LoadFile.');
      Exit;
    end;
  email.Charset := 'utf-8';
  email.SetHtmlBody(html.GetAsString());

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


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