Tcl
Tcl
Specify a Certificate for Encrypted Email
See more Email Object Examples
Demonstrates the Chilkat Email.AddEncryptCert method, which explicitly specifies a certificate to use when sending encrypted email. Call it once per recipient certificate; ClearEncryptCerts clears the list. This example loads a recipient certificate, registers it, and enables encrypted sending.
Background: When encrypting to multiple people, each recipient needs to be able to decrypt with their own private key. S/MIME handles this by encrypting the message's one-time content key separately under each recipient's public certificate and including all of those wrapped keys in the message.
AddEncryptCert is how you build that recipient list — one call per certificate — giving explicit control over exactly whose certificates are used rather than relying on automatic lookup.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Demonstrates the AddEncryptCert method, which explicitly specifies a certificate for
# sending encrypted email. Call it once per recipient certificate. Use ClearEncryptCerts
# to clear the list.
set email [new_CkEmail]
CkEmail_put_Subject $email "Encrypted email"
CkEmail_put_Body $email "Encrypted to the specified recipient certificate(s)."
CkEmail_put_From $email "alice@example.com"
CkEmail_AddTo $email "Bob" "bob@example.com"
# Load a recipient certificate (public key) and add it to the encryption cert list.
set cert [new_CkCert]
set success [CkCert_LoadFromFile $cert "qa_data/certs/recipient.cer"]
if {$success == 0} then {
puts [CkCert_lastErrorText $cert]
delete_CkEmail $email
delete_CkCert $cert
exit
}
set success [CkEmail_AddEncryptCert $email $cert]
if {$success == 0} then {
puts [CkEmail_lastErrorText $email]
delete_CkEmail $email
delete_CkCert $cert
exit
}
# Request encrypted sending.
CkEmail_put_SendEncrypted $email 1
puts "Added the recipient's encryption certificate."
# Note: The path "qa_data/certs/recipient.cer" is a relative local filesystem path,
# relative to the current working directory of the running application.
delete_CkEmail $email
delete_CkCert $cert