Java tutorial
import java.util.Properties; import javax.mail.Folder; import javax.mail.Message; import javax.mail.Session; import javax.mail.URLName; public class Main { public static void main(String[] args) throws Exception { URLName server = new URLName("protocol://username:password@host/foldername"); Session session = Session.getDefaultInstance(new Properties(), null); Folder folder = session.getFolder(server); if (folder == null) { System.out.println("Folder " + server.getFile() + " not found."); System.exit(1); } folder.open(Folder.READ_ONLY); // Get the messages from the server Message[] messages = folder.getMessages(); for (int i = 0; i < messages.length; i++) { System.out.println("------------ Message " + (i + 1) + " ------------"); messages[i].writeTo(System.out); } folder.close(false); } }