Java Email Folder receive email from Gmail
import java.util.Properties; import javax.mail.Folder; import javax.mail.Message; import javax.mail.Session; import javax.mail.Store; public class Main { public static void main(String[] args) throws Exception { String host = "pop.gmail.com", protocol = "pop3s"; String username = "usr.some", password = "some.usr"; Properties props = new Properties(); Session session = Session.getInstance(props); session.setDebug(true);/*from w w w .j av a2s.c o m*/ Store store = session.getStore(protocol); store.connect(host, username, password); Folder inbox = store.getFolder("Inbox"); if (inbox.exists()) { inbox.open(Folder.READ_ONLY); Message[] emails = inbox.getMessages(); for (int i = 0; i < emails.length; i++) { System.out.println("Message " + (i + 1)); emails[i].writeTo(System.out); } inbox.close(false); } else System.out.println("Inbox not available"); store.close(); } }