aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Javamail beginners doubt. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Javamail beginners doubt." Watch "Javamail beginners doubt." New topic
Author

Javamail beginners doubt.

Rohit Ahuja
Ranch Hand

Joined: Oct 04, 2001
Posts: 121
Hi guys,
I am having a problem trying to receive mails from a mail server.

I am pasting the code and the error message.

import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class Fetch {
public static void main (String args[]) throws Exception {
String host = "192.100.119.91";

// Get properties
Properties props = System.getProperties();

//props.put("mail.pop3.host", host);


props.put("mail.debug","true");
System.out.println("Here11111111111111111111");
// Get session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);

System.out.println("Here22222222222222222222"+session);
// Get the store
//Store store = session.getStore("imap");
Store store = session.getStore("pop3");
System.out.println("Store%%%%%%%%%%%%%%%%%%"+store);
store.connect(host,"st-oshigoto","stafoshigotoz");
System.out.println("Here33333333333333333333connected");
// Get folder
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
System.out.println("Here44444444444444444444");
// Get directory
Message message[] = folder.getMessages();
System.out.println("Here5555555555555555555");
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();

if (content.length() > 200) {
content = content.substring(0, 200);
}

System.out.print(content);
}
System.out.println("Here666666666666666666");
// Close connection
folder.close(false);
store.close();
System.exit(0);
}
}

Here11111111111111111111
DEBUG: not loading system providers in <java.home>/lib
DEBUG: not loading optional custom providers file: /META-INF/javamail.providers
DEBUG: successfully loaded default providers

DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.
smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.
IMAPStore,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems,
Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: not loading optional address map file: /META-INF/javamail.address.map
Here22222222222222222222javax.mail.Session@44c86f8c
Exception in thread "main" javax.mail.NoSuchProviderException: No provider for pop3
at javax.mail.Session.getProvider(Session.java:249)
at javax.mail.Session.getStore(Session.java:323)
at javax.mail.Session.getStore(Session.java:303)
at Fetch.main(Fetch.java:26)

The problem seems to be occuring on the line
Store store = session.getStore("pop3");

I have included the pop3.jar in the classpath. Can someone tell me where am i going wrong ?

Thnks in advance,
Deepak.
[ October 11, 2005: Message edited by: Deepak A ]

Face Off.
 
jQuery in Action, 2nd edition
 
subject: Javamail beginners doubt.