It's not a secret anymore!
The moose likes Other JSE/JEE APIs and the fly likes java mail api Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "java mail api " Watch "java mail api " New topic

java mail api

pallavi agrawal

Joined: Mar 29, 2004
Posts: 1
i m trying to implement a mail client using java mail api. but i m not able to connect my client to the server.n not able to create a session and authenticate user id n password. how should i proceed?
eammon bannon
Ranch Hand

Joined: Mar 16, 2004
Posts: 140
Can we see your error?
Sergiu Truta
Ranch Hand

Joined: Dec 16, 2003
Posts: 121
This is an example for FETCHING messages:
String host = ...;
String username = ...;
String password = ...;
// 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");;
// 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

For more info you might want to check this out. I'm walking the path...
I agree. Here's the link:
subject: java mail api
It's not a secret anymore!