Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void receiveEmail(String host, String mailStoreType, String
- username, String password) {
- try {
- Properties properties = new Properties();
- properties.put("mail.pop3.host", host);
- Session emailSession = Session.getDefaultInstance(properties);
- POP3Store emailStore = (POP3Store) emailSession.getStore(mailStoreType);
- emailStore.connect(username, password);
- //3) create the folder object and open it
- Folder emailFolder = emailStore.getFolder("INBOX");
- emailFolder.open(Folder.READ_ONLY);
- Message[] messages = emailFolder.getMessages();
- for (int i = 0; i < messages.length; i++) {
- Message message = messages[i];
- System.out.println("---------------------------------");
- System.out.println("Email Number " + (i + 1));
- System.out.println("Subject: " + message.getSubject());
- System.out.println("From: " + message.getFrom()[0]);
- System.out.println("Text: " + message.getContent().toString());
- }
- emailFolder.close(false);
- emailStore.close();
- } catch (NoSuchProviderException e) {e.printStackTrace();}
- catch (MessagingException e) {e.printStackTrace();}
- catch (IOException e) {e.printStackTrace();}
- }
- public static void main(String[] args) {
- String host = "malikamar.com";
- String mailStoreType = "pop3";
- String username= "user2@malikamar.com";
- String password= "user2";
- receiveEmail(host, mailStoreType, username, password);
- }
Add Comment
Please, Sign In to add comment