Problem in receiving e-mail (Javamail)

Please help I found the error of "no provider for pop3" when I run the following program in my office (using proxy to internet but the pop3 a/c is work for my outlook to rcv e-mail). However, that's no error prompt out when running at home but nothing to display even there are two msgs in my inbox:

static String host = "pop.account.com";

static String username = "myuser";

static String password = "mypwd";

public static void main(String[] args) {

Properties props = new Properties();

Session session = Session.getDefaultInstance(props, null);

session.setDebug(debug);

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.getFrom()[0] + "\t" + message.getSubject());

}

folder.close(false);

store.close();

.

.

.

Thanks in advance!

iSam

xml168@sinatown.com

>

[1148 byte] By [isam_hk] at [2007-9-26 3:12:04]
# 1
The only time I got the error "no provider for pop3" was when I did not have the pop provider jar in my classpath. Make sure you have %JAVAMAIL_HOME%\pop3.jar in your classpath.
neville_sequeira at 2007-6-29 11:20:07 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Yes, the error is not found after i hv added the file pop3.jar classpath. But still hv two questions:

1. j2ee installation guide said no need to add the javamail classpath when added j2ee.jar. but howcome now i hv to add pop3.jar to the classpath?

2. there has no msg display even my mail box has some msgs (i checked by my Outlook express). below is the debug screen:

DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3

POP3Store,Sun Microsy stems, Inc]

POP3: connecting to host "pop.myaccount.com", port 110

S: +OK incore system mail POP3 Server ready

C: USER xxx

S: +OK core mail

C: PASS yyy

S: +OK 0 message(s) [0 byte(s)]

C: STAT

S: +OK 0 0

C: QUIT

S: +OK core mail

Thanks!

iSam

isam_hk at 2007-6-29 11:20:07 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

> 2. there has no msg display even my mail box has some

> msgs (i checked by my Outlook express). below is the

Some Mailservers don't allow their users to start multiple Sessions at the same time. Or someting like that.

When i opened my JavaMail-App and open a Connection to a Mailserver, then i'm going to logging me in at the Mailserver with my Internet Browser. The Mailserver writes in the Browser, there are 0 new Messages and 0 read Messages. In the truth there are multiple messages. The Problem is: The Mailserver don't allow multiple Sessions. When i close the Connection in my App, I'll see all the Messages in the Browser.

Your problem(?): Perhaps Outlook Express holds the Connection and the Mailserver say to your JavaMail-App, that there are 0 Messages.

In my case, the App threw an Exception like...

javax.mail.MessagingException: Open failed;

nested exception is:

java.io.EOFException: mailbox in use - is another session active ?

...if i would open a second Connection to the Mailserver.

I think, the result of your second question to the Mailserver depends on its Configuration.

Raphael

> debug screen:

>

> DEBUG: getProvider() returning

> javax.mail.Provider[STORE,pop3,com.sun.mail.pop3

> POP3Store,Sun Microsy stems, Inc]

> POP3: connecting to host "pop.myaccount.com", port

> 110

> S: +OK incore system mail POP3 Server ready

> C: USER xxx

> S: +OK core mail

> C: PASS yyy

> S: +OK 0 message(s) [0 byte(s)]

> C: STAT

> S: +OK 0 0

> C: QUIT

> S: +OK core mail

>

>

> Thanks!

>

> iSam

rawul at 2007-6-29 11:20:07 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
Hi Raphael,do u hv any idea to fix the problem because I dont know the config of mailserver very well.Thanks!
isam_hk at 2007-6-29 11:20:07 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

Hi

In the Connection-Routine, of your JavaMail-App, I would catch a java.io.EOFException. Use something like that....

try{

....//Connection....

Message[] messages.... ;//get the Messages-Array

if(messages.length == 0){

System.out.println("There are 0 Messages in your Mailbox. \n\nOr do you have another Session connected? \n If yes, close this, and retry!");

}

catch(java.io.EOFException ex){

String exText = ex.getLocalizedMessage();

if(exText.indexOf("mailbox in use") != -1){ System.out.println("Mailbox is in use. You can't open another Session.");

}

catch(MessagingException me){

//...

}

The Code catches both bad cases (can't open the mailbox; the Mailserver says there are 0 Messages, but there are multiple). But its not a very nice solution. Check this...

Raphael

rawul at 2007-6-29 11:20:07 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

> Please help I found the error of "no provider for

> pop3" when I run the following program in my office

> (using proxy to internet but the pop3 a/c is work for

> my outlook to rcv e-mail). However, that's no error

> prompt out when running at home but nothing to display

> even there are two msgs in my inbox:

>

> static String host = "pop.account.com";

> static String username = "myuser";

> static String password = "mypwd";

>

> public static void main(String[] args) {

>

> Properties props = new Properties();

> Session session = Session.getDefaultInstance(props,

> null);

> session.setDebug(debug);

>

> 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.getFrom()[0] +

> "\t" + message.getSubject());

> }

>

> folder.close(false);

> store.close();

> .

> .

> .

>

> Thanks in advance!

>

> iSam

> xml168@sinatown.com

Try including the pop3.jar file ahead of the j2ee.jar file in the classpath... Seems like the pop provider included in the j2ee.jar is outdated... Good Luck :)

MLomongo at 2007-6-29 11:20:07 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7

Hi! Have tried all the suggestions but still can't display the msgs which I seem in Outlook express even I tried at home. Does anyone hv this experience or will send the code to here for discuss together.

Anyway, thanks for all yr help & looking for further suggestion!

iSam

xml168@sinatown.com

isam_hk at 2007-6-29 11:20:07 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8
The best demonstration code that I have seen for reading email using POP3, or for that matter demo code for most of what you can do with Javamail, is the one that comes with Javamail download. You can find it in %JAVAMAIL_HOME%\demo[\b]
neville_sequeira at 2007-6-29 11:20:07 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9

> Please help I found the error of "no provider for

> pop3" when I run the following program in my office

> (using proxy to internet but the pop3 a/c is work for

> my outlook to rcv e-mail). However, that's no error

> prompt out when running at home but nothing to display

> even there are two msgs in my inbox:

>

> static String host = "pop.account.com";

> static String username = "myuser";

> static String password = "mypwd";

>

> public static void main(String[] args) {

>

> Properties props = new Properties();

> Session session = Session.getDefaultInstance(props,

> null);

> session.setDebug(debug);

>

> 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.getFrom()[0] +

> "\t" + message.getSubject());

> }

>

> folder.close(false);

> store.close();

> .

> .

> .

>

> Thanks in advance!

>

> iSam

> xml168@sinatown.com

Do you have the activation.jar in your Classpath? Using the JavaMail API requires the JavaBeans Activation Framework JAF (Download At: http://java.sun.com/products/javabeans/glasgow/jaf.html). I think the error of "no provider for pop3" depends on the missing of the JAF. I saw no mistake in the code. Check it...

Raphael

rawul at 2007-6-29 11:20:07 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 10
I forgot:Do you wrote this at the top of your code?import javax.mail.*; //already done, I guess...import javax.activation.*;//for the JAF
rawul at 2007-6-29 11:20:08 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 11

hi there!

i receive an error while fetching mail as

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/SharedByteArrayInputStream

at com.sun.mail.pop3.Protocol.multilineCommand(Protocol.java:284)

at com.sun.mail.pop3.Protocol.top(Protocol.java:179)

at com.sun.mail.pop3.POP3Message.loadHeaders(POP3Message.java:392)

at com.sun.mail.pop3.POP3Message.getSize(POP3Message.java:89)

at msgshow.dumpPart(msgshow.java:221)

at msgshow.main(msgshow.java:200)

can any one help me

my mail id is ssbreddy@yahoo.com

thanks in advance

sudarshan

shony at 2007-6-29 11:20:08 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 12

Hv tried to add pop3.jar in classpath, the error 'no provider' is not found. But the msg still cant be shown which I can see in my Outlook prog. I think the better solution is post my full testing prog. to here & let u try & run:

import java.io.*;

import java.util.*;

import java.net.InetAddress;

import javax.mail.*;

import javax.mail.internet.*;

import javax.activation.*;

public class RecvMail {

static String host = "pop.myaccount.com";

static String username = "myuser";

static String password = "mypwd";

public static void main(String[] args) {

// Create empty properties

Properties props = new Properties();

Session session = Session.getDefaultInstance(props, null);

session.setDebug(true);

try {

Store store = session.getStore("pop3");

store.connect(host, username, password);

Folder folder = store.getFolder("Inbox");

folder.open(Folder.READ_ONLY);

Message message[] = folder.getMessages();

System.out.println(message.length);

for (int i=0, n=message.length; i<n; i++) {

System.out.println(i + ": " + message.getFrom()[0] + "\t" + message.getSubject());

}

folder.close(false);

store.close();

} catch (MessagingException mex) {

mex.printStackTrace();

Exception ex = null;

if ( (ex=mex.getNextException()) != null ) {

ex.printStackTrace();

}

}

}

}

PLs let me know what's yr result.

THanks!

iSam

>

isam_hk at 2007-6-29 11:20:08 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 13

I tried your program. It works just fine other than the fact that I had to fix a syntax error to compile it.

I change the line...

System.out.println(i + ": " + message.getFrom()[0] + "\t" + message.getSubject());

to

System.out.println(i + ": " + message[i].getFrom() + "\t" + message[i].getSubject());

After I fixed the syntax error, I was able to run it against my pop mail server and see all messages both old and new.

neville_sequeira at 2007-6-29 11:20:08 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 14

Yes, now can show the number of new mails in my mail box but cant show the sunject as the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/Sha

redByteArrayInputStream

at com.sun.mail.pop3.Protocol.multilineCommand(Protocol.java:284)

at com.sun.mail.pop3.Protocol.top(Protocol.java:179)

at com.sun.mail.pop3.POP3Message.loadHeaders(POP3Message.java:392)

at com.sun.mail.pop3.POP3Message.getHeader(POP3Message.java:217) at javax.mail.internet.MimeMessage.getAddressHeader(MimeMessage.java:432)

at javax.mail.internet.MimeMessage.getFrom(MimeMessage.java:197)

at RecvMail.main(RecvMail.java:39)

isam_hk at 2007-6-29 11:20:08 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 15

Hi

Ive successfully compiled ur code after changing the line

System.out.println(i + ": " + message.getFrom() + "\t" + message.getSubject());

But, the following error comes...

DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.

POP3Store,Sun Microsy stems, Inc]

POP3: connecting to host "pop.mail.yahoo.com", port 110

javax.mail.MessagingException: Connect failed;

nested exception is:

java.net.UnknownHostException: pop.mail.yahoo.com

at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:106)

at javax.mail.Service.connect(Service.java:234)

at javax.mail.Service.connect(Service.java:135)

at RMail.main(RMail.java:24)

java.net.UnknownHostException: pop.mail.yahoo.com

at java.net.InetAddress.getAllByName0(InetAddress.java:571)

at java.net.InetAddress.getAllByName0(InetAddress.java:540)

at java.net.InetAddress.getByName(InetAddress.java:449)

at java.net.Socket.<init>(Socket.java:100)

at com.sun.mail.util.SocketFetcher.getSocket0(SocketFetcher.java:131)

at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:113)

at com.sun.mail.pop3.Protocol.<init>(Protocol.java:61)

at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:159)

at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:102)

at javax.mail.Service.connect(Service.java:234)

at javax.mail.Service.connect(Service.java:135)

at RMail.main(RMail.java:24)

Im always on Internet, but we use proxy to connect to the Network NT Server in which DSL connection is there. So, please tell me how to connect thru proxy. Also, I need to connect from a JSP page. Not from a java file. If uve code for JSP, can u give that please.

Yours,

Jini Shans

jinihailstorm at 2007-7-1 3:29:13 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 16
Hi,Actually I need to retrive the body of new messages automatically when a new mail comes, and update in my Oracle DB.Yours,Jini Shans
jinihailstorm at 2007-7-1 3:29:13 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 17

hi

i have sucessfully write the receiving mail using javamail with pop3 protocol.using run the Jakarta Tomcat 4/1.2.27 server.

while run the application the following error comes...

java.lang.NoSuchMethodError

at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:160)

at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:102)

at javax.mail.Service.connect(Service.java:227)

at javax.mail.Service.connect(Service.java:131)

at vinoth.MailAccessor.handleMessages(MailAccessor.java:79)

at vinoth.MailAccessor.doGet(MailAccessor.java:30)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)

at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)

at java.lang.Thread.run(Thread.java:479)

--

VinothPandian at 2007-7-1 3:29:13 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...