VB.NET Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VB.NET Examples

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

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

Byte Array
VB.NET FTPS
System.IO

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

 

 

 

 

 

 

How to Process a Large IMAP Mailbox

Demonstrates how to process a mailbox containing a large number of emails. This example was prompted by a Chilkat customer who needed to efficiently process a mailbox with over 100,000 emails. The technique is to first select the mailbox, which updates the imap.NumMessages property to reflect the number of messages in the mailbox. The emails in the mailbox have sequence numbers ranging from 1 to NumMessages. Two new methods, FetchSequence and FetchSequenceHeaders, can then be used to fetch emails based on sequence number ranges.

Download Chilkat .NET for 2.0 Framework

Download Chilkat .NET for 1.0 / 1.1 Framework

Dim imap As New Chilkat.Imap()

Dim success As Boolean

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


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


'  Login
success = imap.Login("admin@chilkatsoft.com","*myPassword5*")
If (success <> true) Then
    MsgBox(imap.LastErrorText)
    Exit Sub
End If


'  Our experience has been that with some IMAP servers,
'  the response time for selecting a mailbox increases with
'  the size of the mailbox.  You may need to increase the
'  ReadTimeout to a value larger than the default of 30 seconds.
'  In this case, it is set to 60 seconds.
imap.ReadTimeout = 60

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


'  After selecting a mailbox, the NumMessages property will
'  be updated to reflect the total number of emails in the mailbox:
TextBox1.Text = TextBox1.Text & imap.NumMessages & vbCrLf
TextBox1.Refresh()

'  The emails in the mailbox will always have sequence numbers
'  ranging from 1 to NumMessages.  There are two new methods
'  that can be called to fetch emails for a range of sequence
'  numbers: FetchSequence and FetchSequenceHeaders.
'  They are identical except one returns full emails whereas
'  the other returns headers-only.

'  This example assumes there are more than 10 emails in the
'  mailbox and fetches the 1st 10 emails:
Dim bundle As Chilkat.EmailBundle
Dim startSeqNum As Long
startSeqNum = 1
Dim numToFetch As Long
numToFetch = 10
bundle = imap.FetchSequence(startSeqNum,numToFetch)
If (bundle Is Nothing ) Then
    MsgBox(imap.LastErrorText)
    Exit Sub
End If


'  Print the From and Subject of each email:
Dim i As Long
For i = 0 To bundle.MessageCount - 1
    Dim email As Chilkat.Email
    '  GetEmail does not communication with the IMAP server.
    '  It simply extracts a single email from the in-memory bundle.
    email = bundle.GetEmail(i)

    TextBox1.Text = TextBox1.Text & email.From & vbCrLf
    TextBox1.Refresh()
    TextBox1.Text = TextBox1.Text & email.Subject & vbCrLf
    TextBox1.Refresh()

    TextBox1.Text = TextBox1.Text & "--" & vbCrLf
    TextBox1.Refresh()

Next

'  Disconnect from the IMAP server.
imap.Disconnect()


 

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

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

Mail Component · XML Parser