Sample code for 30+ languages & platforms
Android™

Fetch the UIDLs of All POP3 Messages

See more POP3 Examples

Demonstrates the Chilkat MailMan.FetchUidls method, which retrieves the UIDLs of the messages currently in the POP3 mailbox and stores them in a StringTable, one entry per message, in the server's current mailbox order. This example lists every UIDL.

Background: The UIDL list is the starting point for incremental mail retrieval. A client keeps a record of the UIDLs it has already downloaded; on each check it fetches the current list, computes the difference, and downloads only the new ones (see FetchUidlSet). This is how "leave a copy on the server" works without repeatedly re-downloading the same messages.

Chilkat Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean success = false;

    //  Demonstrates the MailMan.FetchUidls method, which retrieves the UIDLs of the messages
    //  currently in the POP3 mailbox and stores them in a StringTable, one entry per message, in
    //  the server's current mailbox order.

    CkMailMan mailman = new CkMailMan();

    //  Configure the POP3 server connection.
    mailman.put_MailHost("pop.example.com");
    mailman.put_MailPort(995);
    mailman.put_PopSsl(true);
    mailman.put_PopUsername("user@example.com");
    mailman.put_PopPassword("myPassword");

    //  Retrieve the UIDLs of all messages in the mailbox.
    CkStringTable uidls = new CkStringTable();

    success = mailman.FetchUidls(uidls);
    if (success == false) {
        Log.i(TAG, mailman.lastErrorText());
        return;
        }

    int n = uidls.get_Count();
    Log.i(TAG, "Mailbox contains " + String.valueOf(n) + " messages.");

    int i;
    for (i = 0; i <= n - 1; i++) {
        Log.i(TAG, "UIDL " + String.valueOf(i) + ": " + uidls.stringAt(i));
        }

    //  Note: Explicitly connecting/authenticating is optional.  Chilkat MailMan automatically
    //  connects and authenticates -- using the property settings above -- whenever a server
    //  operation requires it.  Calling the explicit connect/authenticate methods can still be
    //  helpful to determine whether a failure occurs while connecting or while authenticating.

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}