Session getStore Example
Session class getStore example. This example shows you how to use getStore method.
Session class getStore example. public Store getStore() throws NoSuchProviderException Get a Store object that implements this user's desired Store protocol. The mail.store.protocol property specifies the desired protocol. If an appropriate Store object is not obtained, NoSuchProviderException is thrown
Here is the code
/*
* @ # GetStore.java
* A class repersenting use to GetStore method
* of Session class in javax.mail package
* version 07 July 2008
* author Rose India
*/
package session;
import java.util.*;
import javax.mail.*;
public class GetStore {
public static void main(String args[]) throws Exception {
String server = "192.168.10.205";
String username = "test";
String password = "test";
Properties properties = System.getProperties();
Session session = Session.getDefaultInstance(properties, null);
Store store = session.getStore("pop3");
store.connect(server, username, password);
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message[] messages = folder.getMessages();
for (int i = 0; i < messages.length; i++) {
System.out.println("Date : " + messages[i].getSentDate());
System.out.println("From : " + messages[i].getFrom()[0]);
System.out.println("Subject : " + messages[i].getSubject());
System.out.println("Content : " + messages[i].getContent());
}
}
} |
Output
Date : Mon Jul 07 22:54:32 IST 2008
From : test@localhost
Subject : Abc
Content : hi Abc ..!
Date : Mon Jul 07 22:40:55 IST 2008
From : test@localhost
Subject : komal
Content : JavaMail
Date : Mon Jul 07 22:41:29 IST 2008
From : test@localhost
Subject : komal
Content : JavaMail |
|