Java Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Java Examples

Quick Start
Unicode
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
SFTP
Signatures
SMTP
Socket / SSL
Spider
SSH
SSH Key
SSH Tunnel
Tar
Upload
XML
XMP
Zip

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

Unreleased...
Bzip2
LZW
Icon

 

 

 

 

 

 

 

Read IMAP Email Headers

Call FetchHeaders to download only the email headers.

Download Chilkat Java Library

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkImap imap = new CkImap();

    boolean success;

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

    //  Connect to an IMAP server.
    success = imap.Connect("mail.chilkatsoft.com");
    if (success != true) {
        System.out.println(imap.lastErrorText());
        return;
    }

    //  Login
    success = imap.Login("****","****");
    if (success != true) {
        System.out.println(imap.lastErrorText());
        return;
    }

    //  Select an IMAP mailbox
    success = imap.SelectMailbox("Inbox");
    if (success != true) {
        System.out.println(imap.lastErrorText());
        return;
    }

    CkMessageSet messageSet;
    //  We can choose to fetch UIDs or sequence numbers.
    boolean fetchUids;
    fetchUids = true;
    //  Get the message IDs of all the emails in the mailbox
    messageSet = imap.Search("ALL",fetchUids);
    if (messageSet == null ) {
        System.out.println(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.
    CkEmailBundle bundle;
    bundle = imap.FetchHeaders(messageSet);
    if (bundle == null ) {

        System.out.println(imap.lastErrorText());
        return;
    }

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

        //  Display the From and Subject
        System.out.println(email.ck_from());
        System.out.println(email.subject());

        //  Display the recipients:
        int j;
        String name;
        String addr;
        for (j = 0; j <= email.get_NumTo() - 1; j++) {
            name = email.getToName(j);
            addr = email.getToAddr(j);
            System.out.println(name + ", " + addr);
        }

        for (j = 0; j <= email.get_NumCC() - 1; j++) {
            name = email.getCcName(j);
            addr = email.getCcAddr(j);
            System.out.println(name + ", " + addr);
        }

        //  Show the total size of the email, including body and attachments:
        System.out.println(email.get_Size());

        //  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 = (int) imap.GetMailNumAttach(email);
        for (j = 0; j <= numAttach - 1; j++) {
            System.out.println(imap.getMailAttachFilename(email,j));
            int attachSize;
            attachSize = (int) imap.GetMailAttachSize(email,j);
            System.out.println("    size = "
                 + attachSize + " bytes");
        }

        System.out.println("--");

    }

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