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
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

Download IMAP Email Headers

Download Chilkat .NET for 2.0 / 3.5 Framework

Download Chilkat .NET for 1.0 / 1.1 Framework

C# sample code to download email headers from an IMAP mailbox and display From, To, CC, Subject, Date, and Attachment information.

    private void button3_Click(object sender, System.EventArgs e)
    {
	// Read email headers and display the FROM, Subject, To, CC,
	// Date, and Attachment info.
	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 a message set containing all the message IDs
	// in the selected mailbox.
	bool fetchUids = true;
	Chilkat.MessageSet mset = imap.Search("ALL",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.  
	    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();		
    }
 

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

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

Email Component · XML Parser