code sample for Yahoo! mail POP connection.
843830Nov 15 2001 — edited May 11 2003Here is code for connecting to Yahoo! mail through POP. The Yahoo! mailbox must be set up to allow POP access. (Pick Options, then POP Access & Forwarding and then choose Web and POP Access. Note that you must enable Yahoo! Delivers [but don't need to subscribe to anything])
(So far I have only attempted to READ my inbox and not tried to send. I suspect from other messages in this forum that I need to make an smtp connection in order to send).
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
store = session.getStore("pop3");
store.connect("pop.mail.yahoo.com", getUsername(), getPassword());
folder = store.getFolder("INBOX");
System.out.println(folder.getMessageCount());
// getFolder returns -1 because the folder is closed.
folder.open(Folder.READ_ONLY);
System.out.println(folder.getMessageCount());
Message message[] = folder.getMessages();
for (int x=0, n=message.length; x<n; x++) {
System.out.println(i + ": " + message[x].getFrom() + "\t" + message[x].getSubject());
}
folder.close(false);
store.close();