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

POP3 Fetch Mime Source of Email by UIDL

Demonstrates how to fetch the MIME source of a single email by UIDL.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.BinData;
import com.chilkatsoft.chilkat2.ChilkatException;
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 as MIME.
        BinData bdMime = new BinData();

        int count = stUidls.getCount();
        int i = 0;
        while (i < count) {
            try {
                mailman.fetchMimeBd(stUidls.stringAt(i), bdMime);
            } catch (ChilkatException e) {
                System.out.println(e.getLastErrorText());
                return;
            }

            // Do whatever is needed with the MIME contained in bdMime.

            i = i + 1;
        }
    }
}