Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Receiving Signed or Encrypted Email
VB6 sample program showing how to received signed and/or encrypted mail. ' This example discusses how signed and/or encrypted email is received
' using the Chilkat Email Component.
Private Sub Command16_Click()
Dim mailman As New ChilkatMailMan2
mailman.UnlockComponent "Anything for 30-day trial"
' By default, the mailman.AutoUnwrapSecurity property has a default value = 1
' This means that signed and/or encrypted emails are automatically "unwrapped"
' when received. Digitally signed emails are automatically verified,
' and encrypted emails are automatically decrypted. Your application receives
' the email object as if it were never signed/encrypted.
' When Chilkat verifies signatures or decrypts, it will set properties on
' the email object to allow for your program to know what happened. To summarize:
'
' (Property) ChilkatEmail2.Decrypted -- 1 if received encrypted and successfully decrypted, otherwise 0
' (Property) ChilkatEmail2.EncryptedBy -- Certificate Subject Name of the encrypting certificate if the email was received encrypted.
' (Property) ChilkatEmail2.ReceivedEncrypted -- 1 if the email was received encrypted.
' (Property) ChilkatEmail2.ReceivedSigned -- 1 if the email was received signed.
' (Property) ChilkatEmail2.SignaturesValid - 1 if received signed AND the signatures were valid.
' (Property) ChilkatEmail2.SignedBy -- Certificate Subject Name of the signing certificate.
' (Method) ChilkatEmail2.GetEncryptedByCert -- Returns the certificate used for encryption.
' (Method) ChilkatEmail2.GetSignedByCert -- Returns the certificate used for signing.
' Set our mail host and login
mailman.MailHost = "mail.chilkatsoft.com"
mailman.PopUsername = "****"
mailman.PopPassword = "****"
' This is the default, so we really don't need to set it...
mailman.AutoUnwrapSecurity = 1
Dim bundle As ChilkatEmailBundle2
Dim email As ChilkatEmail2
Set bundle = mailman.CopyMail()
If (bundle Is Nothing) Then
MsgBox mailman.LastErrorText
Exit Sub
End If
Dim cert As ChilkatCert
' Examine each email to see if it was received signed/encrypted.
n = bundle.MessageCount
For i = 0 To n - 1
Set email = bundle.GetEmail(i)
List1.AddItem email.From + ": " + email.Subject
If (email.ReceivedEncrypted = 1) Then
List1.AddItem "---- Received Encrypted!"
List1.AddItem "---- Certificate Subject Name: " + email.EncryptedBy
' Was it successfully decrypted?
' Note: Decrypted is only applicable when ReceivedEncrypted = 1
If (email.Decrypted = 1) Then
List1.AddItem "---- Successfully Decrypted!"
Else
List1.AddItem "---- NOT Decrypted!"
End If
Set cert = email.GetEncryptedByCert()
' We can check many properties of the certificate:
' cert.Expired = 1 if expired, otherwise 0
' cert.Revoked = 1 if revoked, otherwise 0
' cert.TrustedRoot = 1 if the root is a trusted root, otherwise 0
' cert.SignatureVerified = 1 if the certificate's signature was verified, otherwise 0
End If
If (email.ReceivedSigned = 1) Then
List1.AddItem "---- Received Signed!"
List1.AddItem "---- Certificate Subject Name: " + email.SignedBy
' Was it successfully verified?
' Note: SignaturesValid is only applicable when ReceivedSigned = 1
If (email.SignaturesValid = 1) Then
List1.AddItem "---- Signature Verified!"
Else
List1.AddItem "---- Signature NOT Verified!"
End If
Set cert = email.GetSignedByCert()
' We can check many properties of the certificate:
' cert.Expired = 1 if expired, otherwise 0
' cert.Revoked = 1 if revoked, otherwise 0
' cert.TrustedRoot = 1 if the root is a trusted root, otherwise 0
' cert.SignatureVerified = 1 if the certificate's signature was verified, otherwise 0
End If
Next
End Sub
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.