Import java. util. properties;
Import javax. Mail. folder;
Import javax. Mail. message;
Import javax. Mail. Session;
Import javax. Mail. store;
Public class program {
/**
* @ Param ARGs
* @ Throws exception
*/
Public static void main (string [] ARGs) throws exception {
String host = "imap.gmail.com ";
Int Port = 993;
String user = "xxxxx@gmail.com ";
String Password = "XXXXX ";
String target_folder = "inbox ";
Properties props = system. getproperties ();
Session sess = session. getinstance (props, null );
// Sess. setdebug (true );
Store ST = sess. getstore ("IMAPs ");
St. Connect (host, port, user, password );
Folder fol = ST. getfolder (target_folder );
If (fol. exists ()){
For (Folder F: fol. List ()){
System. Out. println (F. getname ());
}
Fol. Open (Folder. read_only );
For (message M: fol. getmessages ()){
System. Out. printf ("% s-% d/N", M. getsubject (), M. getsize ());
}
Fol. Close (false );
} Else {
System. Out. printf ("% s is not exist.", target_folder );
}
St. Close ();
}
}