Sample code for 30+ languages & platforms
Java

Find the "Sent" IMAP Mailbox

See more IMAP Examples

Find the "Sent" IMAP mailbox. Also finds the Junk and Trash mailboxes..

Chilkat Java Downloads

Java
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[])
  {
    boolean success = false;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkImap imap = new CkImap();

    imap.put_Ssl(true);
    imap.put_Port(993);
    success = imap.Connect("imap.yourmailserver.com");
    if (success == false) {
        System.out.println(imap.lastErrorText());
        return;
        }

    // Login or authenticate in some way..
    success = imap.Login("your_login","your_password");
    if (success == false) {
        System.out.println(imap.lastErrorText());
        return;
        }

    // Get the list of mailboxes.
    String refName = "";
    String wildcardedMailbox = "*";
    boolean subscribed = false;

    CkMailboxes mboxes = new CkMailboxes();
    success = imap.MbxList(subscribed,refName,wildcardedMailbox,mboxes);
    if (success == false) {
        System.out.println(imap.lastErrorText());
        return;
        }

    // The mailbox with the "/Sent" flag is the "Sent" mailbox.
    // Likewise for Junk and Trash..
    int i = 0;
    while (i < mboxes.get_Count()) {
        if (mboxes.HasFlag(i,"\\Sent") == true) {
            System.out.println("Sent mailbox: " + mboxes.getName(i));
            }

        if (mboxes.HasFlag(i,"\\Junk") == true) {
            System.out.println("Junk mailbox: " + mboxes.getName(i));
            }

        if (mboxes.HasFlag(i,"\\Trash") == true) {
            System.out.println("Trash mailbox: " + mboxes.getName(i));
            }

        i = i+1;
        }

    // Disconnect from the IMAP server.
    success = imap.Disconnect();
  }
}