Guest User

Untitled

a guest
Nov 21st, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. public static void receive(String popServer, String popUser, String popPassword){
  2. Store store = null;
  3. Folder folder = null;
  4. try {
  5. // -- Get hold of the default session --
  6. Properties props = System.getProperties();
  7. Session session = Session.getDefaultInstance(props, null);
  8. // -- Get hold of a POP3 message store, and connect to it --
  9. store = session.getStore("pop3");
  10. store.connect(popServer, popUser, popPassword);
  11.  
  12. // -- Try to get hold of the default folder --
  13. folder = store.getDefaultFolder();
  14. if (folder == null) throw new Exception("No default folder");
  15.  
  16. // -- ...and its INBOX --
  17. folder = folder.getFolder("INBOX");
  18. if (folder == null) throw new Exception("No POP3 INBOX");
  19.  
  20. // -- Open the folder for read only --
  21. folder.open(Folder.READ_ONLY);
  22.  
  23. // -- Get the message wrappers and process them --
  24. Message[] msgs = folder.getMessages();
  25. for (int msgNum = 0; msgNum < msgs.length; msgNum++) {
  26. printMessage(msgs[msgNum]);
  27. }
  28. } catch (Exception ex) {
  29. ex.printStackTrace();
  30. } finally {
  31. // -- Close down nicely --
  32. try {
  33. if (folder!=null) folder.close(false);
  34. if (store!=null) store.close();
  35. } catch (Exception ex2) {
  36. ex2.printStackTrace();
  37. }
  38. }
  39. }
Add Comment
Please, Sign In to add comment