import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;


public class ReceiveUseAuthenticator{
	public static void main(String[] args){

	try{
		//设置属性值
		Properties props = System.getProperties();
		props.put("mail.pop3.host", "onecompany.com");

		//Authenticator子类实例化
		Authenticator auth = new SwingAuthenticator();
 
		//获得Session
		Session session = Session.getDefaultInstance(props,auth);
		//session.setDebug(true);


		//设置Store、Folder,检索消息
		Store store=session.getStore("pop3");	
		store.connect();
 
		Folder folder=store.getFolder("INBOX");
		folder.open(Folder.READ_ONLY);	

		Message message[]=folder.getMessages();

		Address address;
		int n=message.length;
		for(int i=0;i<n;i++){
			address=message[i].getFrom()[0];
			System.out.println(i+":"+address.toString()+"\t"
						+message[i].getSubject());
		}

		folder.close(false);
		store.close();
        }catch(Exception e){}

	System.exit(0);
	}
}

