Java Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Java Examples

Quick Start
Java Unicode
Java Certs
Java Email
Java Encryption
Java FTP
HTML-to-XML
Java HTTP
Java IMAP
Java MHT
Java MIME
Java RSA
Java S/MIME
Java Signatures
Java Socket
Java Spider
Java Tar
Java Upload
Java XML
Java XMP
Java Zip

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

Unreleased...
Bzip2
LZW
Bz2
Icon

 

 

 

 

 

 

 

Fetch Single Email by UID or Sequence Number

Assuming the UID is known, download a single email by UID from an IMAP mail server.

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;
    }

    CkEmail email;

    int uid;
    uid = (int) 2014;
    boolean isUid;
    isUid = true;

    email = imap.FetchSingle(uid,isUid);
    if (!(email == null )) {

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

        //  Display the Body property, which is the default body.
        //  If an email has an HTML body, the Body property contains
        //  the HTML source.  Otherwise it contains the plain-text
        //  body.
        System.out.println("---- EMAIL BODY ----");
        System.out.println(email.body());
        System.out.println("--------------------");

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

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

        //  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);
        System.out.println(numAttach);

        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.