Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

How can i read message with Java Mail API?
If you want to read the Mail or Messages using for JavaMail API. There are all messages are stored in a Folder object. and this folder contains to all folders and messages. Some important methods are inbuit in this program.
Session.getProperties();
session.getstore("pop3")
store.connect(hostname,username,and password)
store.getFolder("inbox")
folder.open(Folder.READ_ONLY),folder.getMessages().

public class readmail 
{ 
 public static void main(String args[]) 
 { 
  String host = "192.168.10.255";
  String username = "r4r@localhost";
  String password = "r4r@localhost"; 
Properties props = new Properties();
// Get session
Session session = Session.getDefaultInstance(props, null);
// Get the store
Store store = session.getStore("pop3");
store.connect(host, username, password);
// Get folder
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
// Get directory
Message message[] = folder.getMessages();
for (int i=0; n=message.length; i<n; i++) {
   System.out.println(i + ": " + message[i].getFrom()[0] 
     + "	" + message[i].getSubject());
}
// Close connection 
folder.close(false);
store.close();
}
}
Posted By: Name:Rajesh Kr URL: How can i read message with Java Mail API?