C# Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

C# Examples

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


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

Unreleased...
Bzip2
LZW
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

Chilkat.Imap imap = new Chilkat.Imap();

bool success;

//  Anything unlocks the component and begins a fully-functional 30-day trial.
success = imap.UnlockComponent("Anything for 30-day trial");
if (success != true) {
    MessageBox.Show(imap.LastErrorText);
    return;
}

//  Connect to an IMAP server.
success = imap.Connect("mail.chilkatsoft.com");
if (success != true) {
    MessageBox.Show(imap.LastErrorText);
    return;
}

//  Login
success = imap.Login("admin@chilkatsoft.com","*myPassword5*");
if (success != true) {
    MessageBox.Show(imap.LastErrorText);
    return;
}

//  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) {
    MessageBox.Show(imap.LastErrorText);
    return;
}

//  After selecting a mailbox, the NumMessages property will
//  be updated to reflect the total number of emails in the mailbox:
textBox1.Text += imap.NumMessages + "\r\n";
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:
Chilkat.EmailBundle bundle;
int startSeqNum;
startSeqNum = 1;
int numToFetch;
numToFetch = 10;
bundle = imap.FetchSequence(startSeqNum,numToFetch);
if (bundle == null ) {
    MessageBox.Show(imap.LastErrorText);
    return;
}

//  Print the From and Subject of each email:
int i;
for (i = 0; i <= bundle.MessageCount - 1; i++) {
    Chilkat.Email 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 += email.From + "\r\n";
    textBox1.Refresh();
    textBox1.Text += email.Subject + "\r\n";
    textBox1.Refresh();

    textBox1.Text += "--" + "\r\n";
    textBox1.Refresh();

}

//  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.

Email Component · XML Parser