O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading Email

Properties props = new Properties();
											Session session =
											Session.getDefaultInstance(props, null);
											Store store = session.getStore("pop3");
											store.connect(host, username, password);
											Folder folder = store.getFolder("INBOX");
											folder.open(Folder.READ_ONLY);
											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());
											String content =
											message[i].getContent().toString();
											System.out.print(content.substring(0,100));
											}
											folder.close(false);
											store.close();

In this phrase, we connect to a POP3 email server and retrieve all messages in the INBOX folder. The JavaMail API makes this task quite easy to perform. Here are the general steps ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required