Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

code sample for Yahoo! mail POP connection.

843830Nov 15 2001 — edited May 11 2003
Here 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();
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 8 2003
Added on Nov 15 2001
31 comments
1,745 views