//Import These Classes
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.internet.MimeBodyPart;
String HOST = "pop.mail.yahoo.com";
String USERNAME = "";
String PASSWORD = "";
// Mail Test
Folder folder = null;
Store store = null;
try {
Properties props = new Properties();
props.put("mail.store.protocol", "pop3");
// Google uses POP3S not POP3
Session session = Session.getDefaultInstance(props);
// session.setDebug(true);
store = session.getStore();
store.connect(HOST, USERNAME, PASSWORD);
folder = store.getDefaultFolder().getFolder("SENT");
folder.open(Folder.READ_ONLY);
Message[] messages = folder.getMessages();
//System.out.println("No of Messages : " + folder.getMessageCount());
//System.out.println("No of Unread Messages : "
// + folder.getUnreadMessageCount());
for (int i = 0; i < messages.length; ++i) {
//System.out.println("MESSAGE #" + (i + 1) + ":");
Message msg = messages[i];
String from = "unknown";
if (msg.getReplyTo().length >= 1) {
from = msg.getReplyTo()[0].toString();
} else if (msg.getFrom().length >= 1) {
from = msg.getFrom()[0].toString();
}
//String subject = msg.getSubject();
//System.out.println("Saving ... " + subject + " " + from);
// you may want to replace the spaces with "_"
// the files will be saved into the TEMP directory
//Use msg.getContent() to fetch and manage the contents
System.out.println("From # "+msg.getFrom()[0].toString());
}
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (folder != null) {
try {
folder.close(true);
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (store != null) {
try {
store.close();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}