Java Mail Secure POP3 Client

importjava.util.Properties;
importjavax.mail.Authenticator;
importjavax.mail.Folder;
importjavax.mail.Message;
importjavax.mail.PasswordAuthentication;
importjavax.mail.Session;
importjavax.mail.Store;
publicclassMainClass{
publicstaticvoidmain(String[]ARGs)throwsException{
Propertiesprops=newProperties();
Stringhost="yourserver.edu";
Stringprovider="pop3";
Sessionsession=Session.getDefaultInstance(props,newMailAuthenticator());
Storestore=session.getStore(provider);
store.connect(host,null,null);
Folderinbox=store.getFolder("INBOX");
if(inbox==null){
System.out.println("NoINBOX");
System.exit(1);
}
inbox.open(Folder.READ_ONLY);
Message[]messages=inbox.getMessages();
for(inti=0;i<messages.length;i++){
System.out.println("Message"+(i+1));
messages[i].writeTo(System.out);
}
inbox.close(false);
store.close();
}
}
classMailAuthenticatorextendsAuthenticator{
publicMailAuthenticator(){
}
publicPasswordAuthenticationgetPasswordAuthentication(){
returnnewPasswordAuthentication("username","password");
}
}

下載地址:JavaMailSecurePOP3Client.zip( 2,318 k)

相關詞條

熱門詞條

聯絡我們