Xbase++
Xbase++
Find Certificate for Email Encryption
Demonstrates finding the recipient's certificate in the Windows certificate store and using it to send encrypted email.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oMailman
LOCAL oEmail
LOCAL cRecipientEmailAddr
LOCAL oCert
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oMailman := CreateObject("Chilkat.MailMan")
// Set the SMTP server.
oMailman:SmtpHost := "smtp.example.com"
// Create a new email object
oEmail := CreateObject("Chilkat.Email")
oEmail:Subject := "This email is encrypted"
oEmail:Body := "This is a digitally encrypted mail"
oEmail:From := "Joe <joe@example.com>"
// Emails are encrypted using the recipient's certificate.
cRecipientEmailAddr := "jane@example2.com"
oEmail:AddTo("Jane", cRecipientEmailAddr)
// Indicate that the email is to be sent encrypted.
oEmail:SendEncrypted := 1
// This example demonstrates finding the email encryption certificate
// on a Windows system where the certificate is stored in the Windows
// certificate store.
oCert := CreateObject("Chilkat.Cert")
// The recipient's certificate is used to encrypt.
// (Because the recipient is the only one in possession of the private key to decrypt.)
nSuccess := oCert:LoadByEmailAddress(cRecipientEmailAddr)
IF (nSuccess != 1)
? oCert:LastErrorText
oMailman:destroy()
oEmail:destroy()
oCert:destroy()
RETURN
ENDIF
// Specify the certificate to be used for encryption.
nSuccess := oEmail:SetEncryptCert(oCert)
nSuccess := oMailman:SendEmail(oEmail)
IF (nSuccess != 1)
? oMailman:LastErrorText
ELSE
? "Encrypted Mail Sent!"
ENDIF
oMailman:destroy()
oEmail:destroy()
oCert:destroy()