import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;
public class SimpleRecMail {
public static void main(String[] args) {
String host =
"pop3.163.com";
String username =
"mchotdog_011";
String password =
"mchotdog";
try{
Properties props =
new Properties();
Session session = Session.getDefaultInstance(props,
null);
Store store = session.getStore(
"pop3");
store.connect(host, username, password);
Folder folder = store.getDefaultFolder();
if(folder ==
null)
throw new Exception(
"No default folder");
folder = folder.getFolder(
"INBOX");
if(folder ==
null)
throw new Exception(
"No POP3 INBOX");
folder.open(Folder.READ_ONLY);
Message message[] = folder.getMessages();
for (int i =
0, n = message.length; i < n; i++) {
System.out.println(message[i]);
System.out.println(i +
": " + message[i].getFrom()
+
"\t" + message[i].getSubject());
}
folder.close(
false);
store.close();
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
转载于:https://www.cnblogs.com/bilaisheng/p/10210961.html