Visual Basic Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VB Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
String
Tar
Unicode
Upload
XML
XMP
Zip Compression

More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor


VB Strings
VB Byte Array

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

 

Read S/MIME Encrypted Email

Read S/MIME encrypted email.

Download Chilkat IMAP ActiveX

Dim imap As New ChilkatImap

Dim success As Long

'  Anything unlocks the component and begins a fully-functional 30-day trial.
success = imap.UnlockComponent("Anything for 30-day trial")
If (success <> 1) Then
    MsgBox imap.LastErrorText
    Exit Sub
End If

'  Connect to an IMAP server.
success = imap.Connect("mail.chilkatsoft.com")
If (success <> 1) Then
    MsgBox imap.LastErrorText
    Exit Sub
End If

'  Login
success = imap.Login("myLogin","myPassword")
If (success <> 1) Then
    MsgBox imap.LastErrorText
    Exit Sub
End If

'  Select an IMAP mailbox
success = imap.SelectMailbox("Inbox")
If (success <> 1) Then
    MsgBox imap.LastErrorText
    Exit Sub
End If

'  The AutoUnwrapSecurity method controls whether signed/encrypted emails are automatically
'  decrypted and/or verified.

'  When set to 1, which is the default, security envelopes are automatically "unwrapped"
'  when a message is retrieved from the server. Signed emails are automatically verified, and
'  encrypted emails are automatically decrypted, restoring the email to the original state before
'  signing and/or encrypting. Information about the signing and encrypting certificates can be
'  retrieved from the Email object (methods: GetSignedByCert, GetEncryptedByCert;
'  properties: SignedBy, EncryptedBy, SignaturesValid, Decrypted, ReceivedSigned,
'  ReceivedEncrypted).

'  This example will explicity set AutoUnwrapSecurity to 1, even though it's
'  already the default value:
imap.AutoUnwrapSecurity = 1

'  The NumMessages property contains the number of messages in the selected mailbox.
Dim numToFetch As Long
numToFetch = imap.NumMessages
'  Download all the email in the Inbox.
Dim bundle As ChilkatEmailBundle2
Set bundle = imap.FetchSequence(1,numToFetch)
If (bundle Is Nothing ) Then
    MsgBox imap.LastErrorText
    Exit Sub
End If

'  Loop over the bundle,
Dim i As Long
For i = 0 To bundle.MessageCount - 1
    Dim email As ChilkatEmail2
    Set email = bundle.GetEmail(i)

    Text1.Text = Text1.Text & email.From & vbCrLf
    Text1.Text = Text1.Text & email.Subject & vbCrLf

    '  At this point, if the email was signed and/or encrypted, it is already "unwrapped", i.e.
    '  the email is already decrypted and in a state as if it were never signed or encrypted.
    '  You may check to see if the email was received encrypted or signed, and if so,
    '  whether it was successfully unwrapped and who signed or encrypted it:
    If (email.ReceivedEncrypted = 1) Then

        Text1.Text = Text1.Text & "This email was encrypted when received." & vbCrLf
        If (email.Decrypted = 1) Then
            Text1.Text = Text1.Text & "This email was successfully decrypted.  It was encrypted by:" & vbCrLf
            Text1.Text = Text1.Text & email.EncryptedBy & vbCrLf
        Else
            Text1.Text = Text1.Text & "This email was not decrypted." & vbCrLf
        End If

    End If

    If (email.ReceivedSigned = 1) Then

        Text1.Text = Text1.Text & "This email was signed when received." & vbCrLf
        If (email.SignaturesValid = 1) Then
            Text1.Text = Text1.Text & "The signature was verified.  It was signed by:" & vbCrLf
            Text1.Text = Text1.Text & email.SignedBy & vbCrLf
        Else
            Text1.Text = Text1.Text & "The signature verification failed." & vbCrLf
        End If

    End If

    '  The email's body, HTML body, attachments, etc.
    '  are decrypted and available just like any non-encrypted email.

    Text1.Text = Text1.Text & "--" & vbCrLf

Next

'  Disconnect from the IMAP server.
imap.Disconnect 


Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.