Visual Basic Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

VB Examples

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

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
DH Key Exchange
DSA
FileAccess
RSS
Atom
Self-Extractor
Service
Bzip2
PPMD
Deflate
LZW


VB Strings
VB Byte Array

 

 

 

 

 

 

 

Alternative Ways of Reading POP3 Mail

Download Chilkat Email ActiveX

This example describes various ways that email can be read from a POP3 server using the Chilkat email component.

' This example discusses the various ways of reading email from a POP3 server
' using the Chilkat Email Component.
Private Sub Command17_Click()

    Dim mailman As New ChilkatMailMan2
    mailman.UnlockComponent "Anything for 30-day trial"

    ' Set our mail host and login
    mailman.MailHost = "mail.chilkatsoft.com"
    mailman.PopUsername = "****"
    mailman.PopPassword = "****"
    
    ' In no particular order....
    
    ' ------------------------------------
    ' 1: TransferMail
    ' ------------------------------------
    ' Transfer mail downloads all email from the mailbox and removes
    ' each email downloaded from the POP3 server.
    ' We can set limits on the maximum number of emails to download,
    ' or the maximum size so that any emails larger that the max size are skipped
    ' (and remain on the server)
    mailman.MaxCount = 20   ' Don't download more than 20 messages. Emails not downloaded will remain on the server.
    mailman.SizeLimit = 512000  ' Don't download emails greater than 512,000 bytes in size.
    
    Dim bundle As ChilkatEmailBundle2
    Set bundle = mailman.TransferMail()
    If (bundle Is Nothing) Then
        MsgBox mailman.LastErrorText
        Exit Sub
    End If
    
    ' You may iterate over the bundle to do whatever it is your program needs
    ' to do with each email...
    Dim email As ChilkatEmail2
    n = bundle.MessageCount
    For i = 0 To n - 1
        Set email = bundle.GetEmail(i)
        ' ....
    Next
    
    ' ------------------------------------
    ' 2: CopyMail
    ' ------------------------------------
    ' This is the same as TransferMail, except the mail is left on the POP3 server.
    Set bundle = mailman.CopyMail()
    
    ' ------------------------------------
    ' 3: GetAllHeaders and then get selected emails
    ' on demand via GetFullEmail
    ' ------------------------------------
    ' Download the email headers and 1 or more lines of the body.
    ' A bundle of email objects is returned, but each email in the bundle
    ' will lack the full body, and will not have the attachment information
    ' available.  Attachment information is only fully available when the full
    ' email has been downloaded from a POP3 server.  This is a limitation
    ' of the POP3 protocol (not the Chilkat component).  The IMAP protocol is
    ' more feature rich in that headers can be downloaded to include information
    ' about attachments.
    Set bundle = mailman.GetAllHeaders(1)
    ' Your program can display summary information about each email, such as the
    ' From Address, Recipients, Subject, Date Received, etc.  Your program can
    ' download the full email for any given header by calling GetFullEmail.
    ' This example shows how to download the full email for the 1st header in
    ' the bundle.
    Set email = bundle.GetEmail(0)
    Dim fullEmail As ChilkatEmail2
    Set fullEmail = mailman.GetFullEmail(email)
    ' ....
    
    ' ------------------------------------
    ' 4: GetAllHeaders and then get selected emails
    ' on demand via FetchMultiple
    ' ------------------------------------
    ' Another option is to download the full email for a collection of the header-only
    ' emails.  For example, this is how we would download the full emails for all headers
    ' where the From address is "invoiceRequest@mycompany.com"
    Dim uidlArray As New CkStringArray
    ' Download the headers and build a UIDL array for all emails where the FROM address = "invoiceRequest@mycompany.com"
    Set bundle = mailman.GetAllHeaders(1)
    n = bundle.MessageCount
    For i = 0 To n - 1
        Set email = bundle.GetEmail(i)
        If (email.FromAddress = "invoiceRequest@mycompany.com") Then
            uidlArray.Append email.Uidl
        End If
    Next
    
    Dim bundle2 As ChilkatEmailBundle2
    Set bundle2 = mailman.FetchMultiple(uidlArray)
    ' ....
    ' Now we can delete the emails in bundle2 from the POP3 server.
    success = mailman.DeleteBundle(bundle2)
    ' An alternative way of doing it is to delete via the UIDLs:
    success = mailman.DeleteMultiple(uidlArray)
    If (success = 0) Then
        MsgBox mailman.LastErrorText
        Exit Sub
    End If
        
    ' ------------------------------------
    ' 5: GetUidls and then fetch a set of headers
    ' at a time.
    ' ------------------------------------
    ' For very large mailboxes, there may be so many emails that even downloading
    ' headers is too time consuming.  In this case, you can get the complete set
    ' of UIDLs and then download a chunk of headers at a time.
    '
    Set uidlArray = mailman.GetUidls()
    
    ' Perhaps we want the 1st 50 emails...
    maxIdx = 49
    If (uidlArray.Count < 50) Then
        maxIdx = uidlArray.Count - 1
    End If
    
    ' Get a chunk of up to 50 UIDLs
    Dim uidlChunk As New CkStringArray
    If (uidlArray.Count > 0) Then
        For i = 0 To maxIdx
            uidlChunk.Append (uidlArray.GetString(i))
        Next
    End If
    
    ' Download up to 50 headers.
    Set bundle = mailman.FetchMultipleHeaders(uidlChunk, 1)
    ' ....
    
    
End Sub

 

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