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

Check if an Email Was Received Encrypted

See more Email Object Examples

Demonstrates the read-only Chilkat Email.ReceivedEncrypted property, which is true if the email was originally received with encryption. This records how the message arrived and remains useful even after successful automatic decryption, when the visible body is already the decrypted content. This example loads an email and reports whether it was received encrypted.

Background: When Chilkat loads an encrypted (S/MIME) email and has the recipient's private key available, it decrypts the content automatically — so the body you read is already in the clear. That convenience creates a question: was this message originally protected in transit? ReceivedEncrypted answers it, letting you distinguish a message that was genuinely encrypted end-to-end from one that was sent as plain text. Pair it with Decrypted to confirm decryption actually succeeded.

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;

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

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

begin
  success := False;

  //  Demonstrates the read-only Email.ReceivedEncrypted property, which is true if
  //  this email was originally received with encryption.  It remains meaningful even
  //  after Chilkat automatically decrypts the message.

  email := TEmail.Create;

  success := email.LoadEml('qa_data/eml/received.eml');
  if (success = False) then
    begin
      WriteLn(email.LastErrorText);
      Exit;
    end;

  if (email.ReceivedEncrypted = True) then
    begin
      WriteLn('This email was originally received encrypted.');
    end
  else
    begin
      WriteLn('This email was not received encrypted.');
    end;

  //  Note: Paths such as "qa_data/..." are relative local filesystem paths,
  //  relative to the current working directory of the running application.


  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.