Visual Basic 6.0 Requires Chilkat v11.0.0+
Visual Basic 6.0
Create an encrypted S/MIME file without SMTP
See more Email Object Examples
Encrypt a saved draft for a recipient with an RSA encryption certificate. This example uses AES-256-GCM for the content and RSA-OAEP for the content-encryption key. Confirm these choices are supported by the receiving mail client. RenderToMimeBd produces the protected bytes without submitting mail.
Chilkat Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim email As New ChilkatEmail
success = email.LoadEml("message.eml")
If (success <> 1) Then
Debug.Print email.LastErrorText
Exit Sub
End If
' Use the recipient's public encryption certificate. Its private key stays with the recipient.
Dim cert As New ChilkatCert
success = cert.LoadFromFile("recipient.cer")
If (success <> 1) Then
Debug.Print cert.LastErrorText
Exit Sub
End If
success = email.SetEncryptCert(cert)
If (success <> 1) Then
Debug.Print email.LastErrorText
Exit Sub
End If
email.Pkcs7CryptAlg = "aes-gcm"
email.Pkcs7KeyLength = 256
email.OaepPadding = 1
email.OaepHash = "sha256"
email.OaepMgfHash = "sha256"
email.SendEncrypted = 1
Dim mail As New ChilkatMailMan
Dim rendered As New ChilkatBinData
success = mail.RenderToMimeBd(email,rendered)
If (success <> 1) Then
Debug.Print mail.LastErrorText
Exit Sub
End If
success = rendered.WriteFile("encrypted.eml")
If (success <> 1) Then
Debug.Print "Failed: rendered.WriteFile."
Exit Sub
End If
Debug.Print "Saved encrypted.eml."