Visual Basic Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VB Examples

Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
RSA
S/MIME
SFTP
SMTP
Socket
Spider
SSH
SSH Key
SSH Tunnel
String
Tar
Unicode
Upload
XML
XMP
Zip Compression

More Examples...
Email Object
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA


VB Strings
VB Byte Array

Unreleased...
Bzip2
LZW
Icon

 

 

 

 

 

 

 

Read Encrypted Email

Download Chilkat Email ActiveX

This example demonstrates how to read encrypted email in Visual Basic.

' Demonstrates how to read encrypted email in VB6
Private Sub Command1_Click()

    ' Create the mailman object for receiving email
    Dim mailman As ChilkatMailMan2
    Set mailman = New ChilkatMailMan2
    
    ' Unlock the component
    ' Anything begins the 30-day trial.
    mailman.UnlockComponent UnlockCode.Text

    ' Set our POP3 hostname, login, password
    mailman.MailHost = PopHost.Text
    mailman.PopUsername = PopLogin.Text
    mailman.PopPassword = PopPassword.Text
    
    ' How many messages are on the POP3 server?
    Dim messageCount
    messageCount = mailman.CheckMail
    LogWindow.Text = messageCount & " messages waiting on server" & vbCrLf
    
    ' Copy email from the POP3 server into an email bundle.
    ' Use mailman.TransferMail to move email off the POP3 server.
    Dim bundle As ChilkatEmailBundle2
    Set bundle = mailman.CopyMail
    ' Be sure to check for a "Nothing" return before using
    ' the bundle object...
    If (bundle Is Nothing) Then
        mailman.SaveLastError "copyMailLog.xml"
        Exit Sub
    End If
    
    ' You can save the bundle as XML if desired.
    bundle.SaveXML "bundle.xml"
        
    ' Loop over each message in the bundle
    messageCount = bundle.messageCount
    Dim i As Long
    Dim email As ChilkatEmail2
    For i = 0 To messageCount - 1
    
        Set email = bundle.GetEmail(i)
        
        ' Save each email to an EML file.
        email.SaveEml "email_" + Str(i) + ".txt"
        
        ' When Chilkat Mail reads mail, it automatically "unwraps" the security.
        ' If an email is encrypted, it decrypts and stores the information
        ' about the identity of the encryptor within the email object.
        ' The email object is returned to you as it was just before being encrypted.
        ' The ReceivedEncrypted property is set to 1 if the email was encrypted, otherwise it is 0.
        LogWindow.Text = LogWindow.Text & "message " & i & vbCrLf
        LogWindow.Text = LogWindow.Text & "RECEIVED ENCRYPTED? " & Str(email.ReceivedEncrypted) & vbCrLf
        If (email.ReceivedEncrypted = 1) Then
            LogWindow.Text = LogWindow.Text & "ENCRYPTED BY: " & email.EncryptedBy & vbCrLf
            LogWindow.Text = LogWindow.Text & "DECRYPTED OK?: " & Str(email.Decrypted) & vbCrLf
            
            ' The digital certificate can be retrieved by calling GetEncryptedByCert.
            Dim cert As ChilkatCert
            Set cert = email.GetEncryptedByCert()
            If (Not (cert Is Nothing)) Then
                LogWindow.Text = LogWindow.Text & "CERT SERIAL NUMBER: " & cert.SerialNumber & vbCrLf
            End If
        End If
                
        ' Print some information from the email.
        LogWindow.Text = LogWindow.Text & "from: " & email.From & vbCrLf
        LogWindow.Text = LogWindow.Text & "subject: " & email.Subject & vbCrLf
        LogWindow.Text = LogWindow.Text & "Local Date: " & email.LocalDate & vbCrLf
        
        ' Print the recipients.
        Dim j As Long
        For j = 0 To email.NumTo - 1
            LogWindow.Text = LogWindow.Text & "to: " & email.GetTo(j) & vbCrLf
        Next
        For j = 0 To email.NumCC - 1
            LogWindow.Text = LogWindow.Text & "cc: " & email.GetCC(j) & vbCrLf
        Next
                
        ' Now print the default email body.
        LogWindow.Text = LogWindow.Text & "Body: " & email.Body & vbCrLf
        
        Set email = Nothing
        
        LogWindow.Text = LogWindow.Text & "----" & vbCrLf
        
    Next
        
    Set mailman = Nothing
    
End Sub



 

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

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