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

 

 

 

 

 

 

Read IMAP Email Headers

Call FetchHeaders to download only the email headers.

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("****","****");
if (success != true) {
    MessageBox.Show(imap.LastErrorText);
    return;
}

//  Select an IMAP mailbox
success = imap.SelectMailbox("Inbox");
if (success != true) {
    MessageBox.Show(imap.LastErrorText);
    return;
}

Chilkat.MessageSet messageSet = null;
//  We can choose to fetch UIDs or sequence numbers.
bool fetchUids;
fetchUids = true;
//  Get the message IDs of all the emails in the mailbox
messageSet = imap.Search("ALL",fetchUids);
if (messageSet == null ) {
    MessageBox.Show(imap.LastErrorText);
    return;
}

//  When downloading headers, each email object contains
//  (obviously) the headers, but the body will be missing.
//  Also, attachments will not be included.  However, it is
//  possible to get information about the attachments
//  as well as the complete size of the email.
Chilkat.EmailBundle bundle = null;
bundle = imap.FetchHeaders(messageSet);
if (bundle == null ) {

    MessageBox.Show(imap.LastErrorText);
    return;
}

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

    //  Display the From and Subject
    textBox1.Text += email.From + "\r\n";
    textBox1.Text += email.Subject + "\r\n";

    //  Display the recipients:
    int j;
    string name;
    string addr;
    for (j = 0; j <= email.NumTo - 1; j++) {
        name = email.GetToName(j);
        addr = email.GetToAddr(j);
        textBox1.Text += name + ", " + addr + "\r\n";
    }

    for (j = 0; j <= email.NumCC - 1; j++) {
        name = email.GetCcName(j);
        addr = email.GetCcAddr(j);
        textBox1.Text += name + ", " + addr + "\r\n";
    }

    //  Show the total size of the email, including body and attachments:
    textBox1.Text += email.Size + "\r\n";

    //  When a full email is downloaded, we would use the
    //  email.NumAttachments property in conjunction with the
    //  email.GetMailAttach* methods.
    //  However, when an email object contains only the header,
    //  we need to access the attachment info differently:
    int numAttach;
    numAttach = imap.GetMailNumAttach(email);
    for (j = 0; j <= numAttach - 1; j++) {
        textBox1.Text += imap.GetMailAttachFilename(email,j) + "\r\n";
        int attachSize;
        attachSize = imap.GetMailAttachSize(email,j);
        textBox1.Text += "    size = " + Convert.ToString(attachSize)
             + " bytes" + "\r\n";
    }

    textBox1.Text += "--" + "\r\n";

}

//  Disconnect from the IMAP server.
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