Java Requires Chilkat v11.0.0+
Chilkat2 Java
Find the "Sent" IMAP Mailbox
See more IMAP Examples
Find the "Sent" IMAP mailbox. Also finds the Junk and Trash mailboxes..Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Imap;
import com.chilkatsoft.chilkat2.Mailboxes;
public class ChilkatExample {
public static void main(String[] args) {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Imap imap = new Imap();
imap.setSsl(true);
imap.setPort(993);
try {
imap.connect("imap.yourmailserver.com");
// Login or authenticate in some way..
imap.login("your_login", "your_password");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Get the list of mailboxes.
String refName = "";
String wildcardedMailbox = "*";
boolean subscribed = false;
Mailboxes mboxes = new Mailboxes();
try {
imap.mbxList(subscribed, refName, wildcardedMailbox, mboxes);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// The mailbox with the "/Sent" flag is the "Sent" mailbox.
// Likewise for Junk and Trash..
int i = 0;
while (i < mboxes.getCount()) {
if (mboxes.hasFlag(i, "\\Sent")) {
System.out.println("Sent mailbox: " + mboxes.getName(i));
}
if (mboxes.hasFlag(i, "\\Junk")) {
System.out.println("Junk mailbox: " + mboxes.getName(i));
}
if (mboxes.hasFlag(i, "\\Trash")) {
System.out.println("Trash mailbox: " + mboxes.getName(i));
}
i = i + 1;
}
// Disconnect from the IMAP server.
imap.disconnect();
}
}