Visual FoxPro
Visual FoxPro
Find Certificate for Email Encryption
Demonstrates finding the recipient's certificate in the Windows certificate store and using it to send encrypted email.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loMailman
LOCAL loEmail
LOCAL lcRecipientEmailAddr
LOCAL loCert
lnSuccess = 0
* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loMailman = CreateObject('Chilkat.MailMan')
* Set the SMTP server.
loMailman.SmtpHost = "smtp.example.com"
* Create a new email object
loEmail = CreateObject('Chilkat.Email')
loEmail.Subject = "This email is encrypted"
loEmail.Body = "This is a digitally encrypted mail"
loEmail.From = "Joe <joe@example.com>"
* Emails are encrypted using the recipient's certificate.
lcRecipientEmailAddr = "jane@example2.com"
loEmail.AddTo("Jane",lcRecipientEmailAddr)
* Indicate that the email is to be sent encrypted.
loEmail.SendEncrypted = 1
* This example demonstrates finding the email encryption certificate
* on a Windows system where the certificate is stored in the Windows
* certificate store.
loCert = 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.)
lnSuccess = loCert.LoadByEmailAddress(lcRecipientEmailAddr)
IF (lnSuccess <> 1) THEN
? loCert.LastErrorText
RELEASE loMailman
RELEASE loEmail
RELEASE loCert
CANCEL
ENDIF
* Specify the certificate to be used for encryption.
lnSuccess = loEmail.SetEncryptCert(loCert)
lnSuccess = loMailman.SendEmail(loEmail)
IF (lnSuccess <> 1) THEN
? loMailman.LastErrorText
ELSE
? "Encrypted Mail Sent!"
ENDIF
RELEASE loMailman
RELEASE loEmail
RELEASE loCert