Delphi DLL
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 Delphi DLL Downloads
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
success: Boolean;
mailman: HCkMailMan;
cert1: HCkCert;
cert2: HCkCert;
cert3: HCkCert;
email: HCkEmail;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The mailman object is used for sending and receiving email.
mailman := CkMailMan_Create();
// 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;