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 Mail from a POP3 Server

Download Chilkat Email ActiveX for POP3 / SMTP

(After installing, add a reference to "Chilkat Mail" in your VB6 project.)

VB source code example to read email from a POP3 server.

' Visual Basic example to read mail from a POP3 server
' This example leaves the mail on the POP3 server.
Private Sub Command1_Click()

    ' Create the mail object for sending email.
    Dim mailman As ChilkatMailMan2
    Set mailman = New ChilkatMailMan2
    success = mailman.UnlockComponent("Anything for 30-day trial")
    If (success = 0) Then
    	MsgBox "Failed to unlock"
    	Exit Sub
    End If
        
    ' Set our POP3 hostname an login / password
    mailman.MailHost = "mail.chilkatsoft.com"
    mailman.PopUsername = "matt"
    mailman.PopPassword = "myPassword"
            
    ' Read email from the POP3 server into a mail bundle.
    ' Call TransferMail instead of CopyMail to transfer
    ' it from the POP3 server instead of leaving it on the
    ' POP3 server.
    Dim bundle As ChilkatEmailBundle2
    Set bundle = mailman.CopyMail
    if (bundle Is Nothing) then
    	MsgBox mailman.LastErrorText
    	Exit Sub
    End If
    
    ' Sort the mail by date received.
    bundle.SortByDate 1
    
    ' Save the email bundle as XML.
    ' Call ChilkatMailMan.LoadXmlFile to restore the bundle object.
    bundle.SaveXml "bundle.xml"
    
    ' Loop over each mail 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)
        
        LogWindow.Text = LogWindow.Text & "Message #" & (i + 1) & vbCrLf
        LogWindow.Text = LogWindow.Text & "From: " & email.From & vbCrLf
        LogWindow.Text = LogWindow.Text & "Subject: " & email.Subject & vbCrLf
        
        ' Display the filename of the first attachment, if it exists.
        If (email.NumAttachments() > 0) Then
            LogWindow.Text = LogWindow.Text & "AttachFilename: " & email.GetAttachmentFilename(0) & vbCrLf
        End If
        
        ' Display the GMT date of the email (EmailDate) and the local
        ' date of the email (LocalDate)
        LogWindow.Text = LogWindow.Text & "EmailDate: " & email.EmailDate & vbCrLf
        LogWindow.Text = LogWindow.Text & "LocalDate: " & email.LocalDate & vbCrLf
        
        ' Save the individual email as XML
        email.SaveXml "email" & Str(i + 1) & ".xml"
                
        Set email = Nothing
        
        LogWindow.Text = LogWindow.Text & "----" & vbCrLf
        
    Next
    
End Sub

 

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

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