Get a list of messages from a POP server in Java

Main.java:

import javax.mail.internet.*;
import javax.mail.*;
import java.util.*;
 
public class Main
{
   public static void main(String []args) {
      try {
         String host = "FILL IN POP3 SERVER HERE";
         String user = "FILL IN UN HERE";
         String pass = "FILL IN PW HERE";
  
         Session session = Session.getInstance(System.getProperties(), null);
  
         Store store = session.getStore("pop3");
         store.connect(host, user, pass);
  
         // only "INBOX" is supported
         Folder folder = store.getFolder("INBOX");
 
         // open the folder read-only
         folder.open(Folder.READ_ONLY);
 
         // get all the messages and print from and subject field 
         Message messages[] = folder.getMessages();
         for (int i=0; i<messages.length; i++) {
            System.out.print(messages[i].getMessageNumber() + "t");
            System.out.print(messages[i].getSentDate() + "t");
            System.out.print(messages[i].getFrom()[0] + "t");
            System.out.println(messages[i].getSubject());
         }
 
         // close the folder, but do not delete (expunge) the messages
         folder.close(false);
         store.close();
      }
      catch(Exception e) {
         e.printStackTrace();
      }
   }
}