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

Send an email with a Bcc recipient using SMTP (live send)

See more Email Object Examples

Live send. Load the previously prepared with-attachments.eml, add a Bcc recipient, and pass the Email to MailMan.SendEmail. For a real test, use a relay you control, replace the sample sender and recipients (including the Bcc address) with test mailboxes, and obtain credentials from your application’s secret store.

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

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

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

begin
  success := False;

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

  email := TEmail.Create;
  success := email.LoadEml('with-attachments.eml');
  if (success <> True) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;
  //  Enable this option before adding a blind recipient to the message.
  email.UncommonOptions := 'NoBccHeader';
  success := email.AddBcc('Bcc recipient','bcc@example.net');
  if (success <> True) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;
  mail := TMailMan.Create;
  mail.SmtpHost := 'smtp.example.com';
  mail.SmtpPort := 465;
  mail.SmtpSsl := True;
  mail.RequireSslCertVerify := True;
  mail.SmtpUsername := 'MAIL_USER';
  mail.SmtpPassword := 'MAIL_PASSWORD';
  success := mail.SendEmail(email);
  if (success <> True) then
    begin
      WriteLn(mail.LastErrorText);
      Exit;
    end;
  WriteLn('The SMTP relay accepted the message.');
  success := mail.CloseSmtpConnection();
  if (success <> True) then
    begin
      WriteLn(mail.LastErrorText);
      Exit;
    end;


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