Classic ASP
Classic ASP
S/MIME Encrypt .eml without Sending
See more Email Object Examples
Demonstrates how to encrypt an email using the recipient's digital certificate. This example just encrypts, and does not send the email.Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
' This example requires the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
set email = Server.CreateObject("Chilkat.Email")
success = email.LoadEml("c:/temp/email/unencrypted.eml")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
Response.End
End If
' The email content is encrypted using AES with a 256-bit key, operating in GCM mode, which provides authenticated encryption.
email.Pkcs7CryptAlg = "aes-gcm"
email.Pkcs7KeyLength = 256
email.OaepPadding = 1
email.OaepHash = "sha256"
email.OaepMgfHash = "sha256"
set cert = Server.CreateObject("Chilkat.Cert")
success = cert.LoadFromFile("c/temps/cert/recipient.cer")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( cert.LastErrorText) & "</pre>"
Response.End
End If
email.SendEncrypted = 1
success = email.SetEncryptCert(cert)
set sbSmime = Server.CreateObject("Chilkat.StringBuilder")
' The mailman object applies the encryption by rendering the email according to the instructions (property settings) provided in the email object.
' No email is sent.
set mailman = Server.CreateObject("Chilkat.MailMan")
success = mailman.RenderToMimeSb(email,sbSmime)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( mailman.LastErrorText) & "</pre>"
Response.End
End If
success = sbSmime.WriteFile("c:/temp/encryptedEmail.eml","utf-8",0)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( mailman.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Success!") & "</pre>"
%>
</body>
</html>