Java Requires Chilkat v11.0.0+
Chilkat2 Java
Download POP3 Email using UIDLs
Demonstrates how to download POP3 email by first getting the complete set of UIDLs and then downloading email by calling FetchByUIDL for each UIDL.Chilkat Java Downloads
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");
StringTable stUidls = new StringTable();
try {
mailman.fetchUidls(stUidls);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
Email email = new Email();
int count = stUidls.getCount();
int i = 0;
while (i < count) {
// Download the full email.
try {
mailman.fetchByUidl(stUidls.stringAt(i), false, 0, email);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println(i);
System.out.println("From: " + email.getFrom());
System.out.println("Subject: " + email.getSubject());
i = i + 1;
}
mailman.pop3EndSession();
}
}