Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Delphi DLL Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Delphi DLL) Send Encrypted Email to Multiple Recipients

Demonstrates how to create and send an S/MIME encrypted email to multiple recipients. The digital certificate of each recipient is required. The encrypting/sending process uses each recipient's digital certificate (which internally contains the public key). Each recipient decrypts the received email using his/her private key.

Chilkat for Delphi Downloads

Chilkat non-ActiveX DLL for Delphi

Chilkat ActiveX DLL for Delphi

* The examples here use the non-ActiveX DLL.

uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, MailMan, Cert, Email;

...

procedure TForm1.Button1Click(Sender: TObject);
var
mailman: HCkMailMan;
success: Boolean;
cert1: HCkCert;
cert2: HCkCert;
cert3: HCkCert;
email: HCkEmail;

begin
//  The mailman object is used for sending and receiving email.
mailman := CkMailMan_Create();

//  Any string argument automatically begins the 30-day trial.
success := CkMailMan_UnlockComponent(mailman,'Anything for 30-day trial');
if (success <> True) then
  begin
    Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
    Exit;
  end;

//  Set the SMTP server.
CkMailMan_putSmtpHost(mailman,'smtp.mymailserver.com');

//  Load each recipient's certificate into a Chilkat certificate object.
//  This example loads the certificates from files.  However, the Chilkat
//  certificate object provides other means for loading certificates,
//  such as from in-memory PEM strings, or in-memory binary DER encoded form, etc.
cert1 := CkCert_Create();
success := CkCert_LoadFromFile(cert1,'recipient1.cer');
if (success <> True) then
  begin
    Memo1.Lines.Add(CkCert__lastErrorText(cert1));
    Exit;
  end;
cert2 := CkCert_Create();
success := CkCert_LoadFromFile(cert2,'recipient2.cer');
if (success <> True) then
  begin
    Memo1.Lines.Add(CkCert__lastErrorText(cert2));
    Exit;
  end;
cert3 := CkCert_Create();
success := CkCert_LoadFromFile(cert3,'recipient3.cer');
if (success <> True) then
  begin
    Memo1.Lines.Add(CkCert__lastErrorText(cert3));
    Exit;
  end;

//  Create a new email object
email := CkEmail_Create();

CkEmail_putSubject(email,'This email is encrypted and sent to 3 recipients');
CkEmail_putBody(email,'This is an S/MIME encrypted mail sent to 3 recipients');
CkEmail_putFrom(email,'Chilkat Support <support@chilkatsoft.com>');

//  Make each of the certificates available for encrypting the email
//  by calling AddEncryptCert for each.
success := CkEmail_AddEncryptCert(email,cert1);
if (success = True) then
  begin
    success := CkEmail_AddEncryptCert(email,cert2);
  end;
if (success = True) then
  begin
    success := CkEmail_AddEncryptCert(email,cert3);
  end;
if (success <> True) then
  begin
    Memo1.Lines.Add(CkEmail__lastErrorText(email));
    Exit;
  end;

//  Add 3 recipients to the email (2 TO addresses, and 1 CC address)
success := CkEmail_AddTo(email,'Recipient 1','admin@cknotes.com');
success := CkEmail_AddTo(email,'Recipient 2','somebody001122@yahoo.com');
success := CkEmail_AddCC(email,'Recipient 3','somebody123xyz@gmail.com');

//  Indicate that the email is to be sent encrypted.
CkEmail_putSendEncrypted(email,True);

//  Send the encrypted email...
success := CkMailMan_SendEmail(mailman,email);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
  end
else
  begin
    Memo1.Lines.Add('Encrypted Email Sent!');
  end;

CkMailMan_Dispose(mailman);
CkCert_Dispose(cert1);
CkCert_Dispose(cert2);
CkCert_Dispose(cert3);
CkEmail_Dispose(email);

end;

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.