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

Inspect blind-copy recipients and prepare a shareable copy

See more Email Object Examples

Keep the addressed Email object for SMTP submission. When exporting a copy to share, clear its Bcc collection before saving. Treat intermediate MIME buffers as private because a renderer can preserve blind-copy details.

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.BinData;

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

procedure RunDemo;
var
  success: Boolean;
  email: TEmail;
  i: Integer;
  rendered: TBinData;
  copy: TEmail;

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';
  email.Body := 'Your workshop confirmation.';
  success := email.AddBcc('Archive','archive@example.com');
  if (success <> True) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;
  i := 0;
  while (i < email.NumBcc) do
    begin
      WriteLn('Envelope blind copy: ' + email.GetBccAddr(i));
      i := i + 1;
    end;

  //  Keep the original delivery list intact. Remove blind copies from the export.
  rendered := TBinData.Create;
  success := email.GetMimeBd(rendered);
  if (success <> True) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;
  copy := TEmail.Create;
  success := copy.SetFromMimeBd(rendered);
  if (success <> True) then
    begin
      WriteLn(copy.LastErrorText);
      Exit;
    end;
  copy.ClearBcc();
  success := copy.SaveEml('shareable.eml');
  if (success <> True) then
    begin
      WriteLn(copy.LastErrorText);
      Exit;
    end;
  WriteLn('Bcc entries in shareable copy: ' + copy.NumBcc);


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