Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

Retrieve UIDL's from POP3 Server

Retrieve a list of UIDLs from a POP3 server. UIDLs are unique identifiers, 1 to 70 characters long, composed of characters ranging from 0x21 to 0x7E. These identifiers uniquely distinguish messages within a mailbox and remain consistent across sessions.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Email;
import com.chilkatsoft.chilkat2.MailMan;
import com.chilkatsoft.chilkat2.StringTable;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        MailMan mailman = new MailMan();

        mailman.setMailHost("pop.example.com");

        mailman.setPopUsername("myLogin");
        mailman.setPopPassword("myPassword");

        mailman.setMailPort(995);
        mailman.setPopSsl(true);

        StringTable stUidls = new StringTable();
        try {
            mailman.fetchUidls(stUidls);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Download each email by UIDL.
        Email email = new Email();

        int count = stUidls.getCount();
        int i = 0;
        while (i < count) {
            // Download the full email.
            String uidl = stUidls.stringAt(i);
            try {
                mailman.fetchByUidl(uidl, false, 0, email);
            } catch (ChilkatException e) {
                System.out.println(e.getLastErrorText());
                return;
            }

            System.out.println(i);
            System.out.println("UIDL: " + uidl);
            System.out.println("From: " + email.getFrom());
            System.out.println("Subject: " + email.getSubject());

            i = i + 1;
        }

        mailman.pop3EndSession();
    }
}