Java Requires Chilkat v11.0.0+
Chilkat2 Java
List Email UIDs
List the UIDs of each email in a mailbox.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Imap;
import com.chilkatsoft.chilkat2.MessageSet;
public class ChilkatExample {
public static void main(String[] args) {
Imap imap = new Imap();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Connect to an IMAP server.
// Use TLS
imap.setSsl(true);
imap.setPort(993);
try {
imap.connect("MY-IMAP-DOMAIN");
// Login
imap.login("MY-IMAP-LOGIN", "MY-IMAP-PASSWORD");
// Select an IMAP mailbox
imap.selectMailbox("Inbox");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Get the message IDs of all the emails in the mailbox
// We can choose to fetch UIDs or sequence numbers.
boolean fetchUids = true;
MessageSet messageSet = new MessageSet();
try {
imap.queryMbx("ALL", fetchUids, messageSet);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
int i = 0;
int n = messageSet.getCount();
while (i < n) {
System.out.println(messageSet.getId(i));
i = i + 1;
}
// Disconnect from the IMAP server.
imap.disconnect();
}
}