Java Mail POP3 Client : Email Client « Email « Java Tutorial






import java.util.Properties;

import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;

public class MainClass {

  public static void main(String[] args) throws Exception {

    Properties props = new Properties();

    String host = "yourHost.edu";
    String username = "userName";
    String password = "mypassword";
    String provider = "pop3";

    Session session = Session.getDefaultInstance(props, null);
    Store store = session.getStore(provider);
    store.connect(host, username, password);

    Folder inbox = store.getFolder("INBOX");
    if (inbox == null) {
      System.out.println("No INBOX");
      System.exit(1);
    }
    inbox.open(Folder.READ_ONLY);

    Message[] messages = inbox.getMessages();
    for (int i = 0; i < messages.length; i++) {
      System.out.println("Message " + (i + 1));
      messages[i].writeTo(System.out);
    }
    inbox.close(false);
    store.close();
  }
}
  Download:  JavaMailPOP3Client.zip( 2,313 k)








30.6.Email Client
30.6.1.Java Mail Secure POP3 Client
30.6.2.Java Mail POP3 Client
30.6.3.Swing Client JavaMail