C# Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript



C# Examples

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


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

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

 

 

 

 

 

 

Download IMAP Emails in Sequence Number Range

C# example to download mail messages for a range of sequence numbers.

    private void button7_Click(object sender, System.EventArgs e)
    {
	// Download the headers for emails with sequence numbers in the
	// range from 1 to 10 inclusive.
	Chilkat.Imap imap = new Chilkat.Imap();
	imap.UnlockComponent("Anything for 30-day trial");
	
	// If your IMAP server needs SSL, set the Ssl property = true
	// and set the IMAP port to 993.
	// imap.Ssl = true;
	// imap.Port = 993;
	imap.Connect("mail.chilkatsoft.com");
	
	// Login to an email account.
	bool b = imap.Login("myLogin", "myPassword");
	if (!b)
	{
	    MessageBox.Show("Login Failed!");
	    return;
	}
    
	// Select the mailbox to read.
	b = imap.SelectMailbox("INBOX");
	if (!b)
	{
	    MessageBox.Show(imap.LastErrorText);
	    return;
	}
	
	// Get all messages with sequence numbers in the range from 1 to 10
	// inclusive.
	bool fetchUids = true;
	Chilkat.MessageSet mset = imap.Search("1:10",fetchUids);

	// Fetch the email headers into an email bundle.
	Chilkat.EmailBundle bundle = imap.FetchHeaders(mset);
	if (bundle == null)
	{
	    MessageBox.Show("Failed to fetch headers!");
	    imap.SaveLastError("errorLog.xml");
	    return;
	}

	// Loop over each e-mail in the bundle and display information:
	int i;
	for (i=0; i<bundle.MessageCount; i++)
	{
	    Chilkat.Email email = bundle.GetEmail(i);

	    listBox1.Items.Add("From: " + email.From);
	    listBox1.Items.Add("Subject: " + email.Subject);
	    listBox1.Items.Add(Convert.ToString(email.LocalDate));
	    
	    int numTo = email.NumTo;
	    int j;
	    for (j=0; j<numTo; j++)
	    {
		listBox1.Items.Add("To: " + email.GetTo(j));
	    }
	    
	    int numCC = email.NumCC;
	    for (j=0; j<numCC; j++)
	    {
		listBox1.Items.Add("CC: " + email.GetCC(j));
	    }
	    
	    // NOTE: The BCC recipients are not available in downloaded
	    // email.
	    
	    // Now show attachment information.  Because we downloaded
	    // the headers, the email.NumAttachments property will always
	    // equal 0.  The email.NumAttachments property is set correctly
	    // only when the full emails are downloaded.  Instead, use the
	    // imap.GetMailNumAttach method.
	    int numAttach = imap.GetMailNumAttach(email);
	    for (j=0; j<numAttach; j++)
	    {
		string attachmentFilename = imap.GetMailAttachFilename(email,j);
		int attachmentSize = imap.GetMailAttachSize(email,j);
		listBox1.Items.Add("Attachment: " + attachmentFilename + ", " + 
		    Convert.ToString(attachmentSize) + " bytes");
	    }

	    listBox1.Items.Add("---------------------------------");
	}    
	// Disconnect from the IMAP server.
	imap.Logout();
	imap.Disconnect();	
	
	MessageBox.Show("Finished!");	
    }

Important: The download for this example does not contain the ChilkatDotNet.dll which
must be downloaded and installed separately at http://www.chilkatsoft.com/downloads.asp.
Once installed, add a reference to the DLL in the project by following the instructions at
http://www.example-code.com/vbdotnet/step2.asp

 

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

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

Email Component · XML Parser