Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get the Certificate an Email Was Encrypted By
See more Email Object Examples
Demonstrates the read-only Chilkat Email.EncryptedBy property. If the email was received encrypted, this property contains descriptive details of the certificate used for encryption. It is meaningful only when ReceivedEncrypted is true. To obtain a certificate object rather than descriptive text, use GetEncryptedByCert or LastDecryptCert. This example loads a received email and prints the encryption certificate details.
Background: In S/MIME encryption, the sender encrypts the message using the recipient's public-key certificate — a signed document that binds an identity (name and email) to a public key.
EncryptedBy reports which certificate was used, letting the recipient confirm the message was encrypted specifically for them. To work with the certificate programmatically (inspecting its subject, issuer, expiration, etc.), request the Cert object via GetEncryptedByCert.Chilkat Pascal (Lazarus/Delphi) Downloads
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 Email.EncryptedBy property.
// If the email was received encrypted, EncryptedBy contains the details of
// the certificate used for encryption. It is only meaningful when
// ReceivedEncrypted is true.
email := TEmail.Create;
success := email.LoadEml('qa_data/eml/encrypted.eml');
if (success = False) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
if (email.ReceivedEncrypted = True) then
begin
WriteLn('Encrypted by: ' + email.EncryptedBy);
end
else
begin
WriteLn('This email was not received encrypted.');
end;
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.