Classic ASP
Classic ASP
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 Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
' Demonstrates the SetEncryptCert method, which sets the explicit recipient encryption
' certificate for sending an encrypted email.
set email = Server.CreateObject("Chilkat.Email")
email.Subject = "Encrypted email"
email.Body = "This message will be sent S/MIME encrypted."
email.From = "alice@example.com"
success = email.AddTo("Bob","bob@example.com")
' Load the recipient's certificate (only the public key is needed to encrypt).
set cert = Server.CreateObject("Chilkat.Cert")
success = cert.LoadFromFile("qa_data/certs/recipient.cer")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( cert.LastErrorText) & "</pre>"
Response.End
End If
' Set the explicit recipient encryption certificate.
success = email.SetEncryptCert(cert)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
Response.End
End If
' Request encrypted sending.
email.SendEncrypted = 1
Response.Write "<pre>" & Server.HTMLEncode( "Encryption certificate set.") & "</pre>"
' Note: The path "qa_data/certs/recipient.cer" is a relative local filesystem path,
' relative to the current working directory of the running application.
%>
</body>
</html>