Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Javamail beginners doubt.

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
If you're gonna buy things, buy this thing and I get a fat kickback:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic