JAVA MAIL API

JavaMail Projects

JavaMail Project 1

How can Read mail message using JavaMail API
Previous Home Next

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() .

package R4R;
import java.io.*;
import java.util.*;
import javax.activation.*;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.Transport;
public class readmail 
{ 
	

 

public static void main(String args[]) { String host = "192.168.10.255"; String username = "r4r@localhost"; String password = "r4r@localhost"; // Create empty properties 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] + "\t" + message[i].getSubject()); } // Close connection folder.close(false); store.close(); } }
Previous Home Next