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

Download POP3 Email to MIME

Download the email from a POP3 mailbox directly into MIME, without parsing into email objects.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.BinData;
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.

        // The mailman object is used for receiving (POP3)
        // and sending (SMTP) email.
        MailMan mailman = new MailMan();

        // Set the POP3 server's hostname
        mailman.setMailHost("pop.example.com");

        // Set the POP3 login/password.
        mailman.setPopUsername("myLogin");
        mailman.setPopPassword("myPassword");

        // First, get the complete set of UIDLs for the email in the POP3 mailbox:
        StringTable stUidls = new StringTable();
        try {
            mailman.fetchUidls(stUidls);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Download each email as MIME.
        // If desired, the MIME can be loaded into an email object.
        BinData bdMime = new BinData();
        Email email = new Email();

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

            email.setFromMimeBd(bdMime);
            System.out.println("From: " + email.getFrom());
            System.out.println("Subject: " + email.getSubject());

            i = i + 1;
        }
    }
}