PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_Cert
li_Success = 0
// Demonstrates the SetEncryptCert method, which sets the explicit recipient encryption
// certificate for sending an encrypted email.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
destroy loo_Email
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Email.Subject = "Encrypted email"
loo_Email.Body = "This message will be sent S/MIME encrypted."
loo_Email.From = "alice@example.com"
loo_Email.AddTo("Bob","bob@example.com")
// Load the recipient's certificate (only the public key is needed to encrypt).
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
li_Success = loo_Cert.LoadFromFile("qa_data/certs/recipient.cer")
if li_Success = 0 then
Write-Debug loo_Cert.LastErrorText
destroy loo_Email
destroy loo_Cert
return
end if
// Set the explicit recipient encryption certificate.
li_Success = loo_Email.SetEncryptCert(loo_Cert)
if li_Success = 0 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
destroy loo_Cert
return
end if
// Request encrypted sending.
loo_Email.SendEncrypted = 1
Write-Debug "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.
destroy loo_Email
destroy loo_Cert