Tcl
Tcl
Set the Recipient Encryption Certificate
See more Email Object Examples
Demonstrates the Chilkat Email.SetEncryptCert method, which sets the explicit recipient encryption certificate for sending an encrypted email. This example loads the recipient's certificate, sets it, and enables encrypted sending.
Background: To encrypt a message for a recipient you need their public certificate — hence a
.cer file (no private key) suffices. SetEncryptCert specifies a single recipient certificate; to encrypt for multiple recipients, use AddEncryptCert once per certificate. Either way, setting SendEncrypted to true is what actually requests encryption when the message is sent.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Demonstrates the SetEncryptCert method, which sets the explicit recipient encryption
# certificate for sending an encrypted email.
set email [new_CkEmail]
CkEmail_put_Subject $email "Encrypted email"
CkEmail_put_Body $email "This message will be sent S/MIME encrypted."
CkEmail_put_From $email "alice@example.com"
CkEmail_AddTo $email "Bob" "bob@example.com"
# Load the recipient's certificate (only the public key is needed to encrypt).
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 the explicit recipient encryption certificate.
set success [CkEmail_SetEncryptCert $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 "Encryption certificate set."
# 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