wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Problem regarding JavaMail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Problem regarding JavaMail" Watch "Problem regarding JavaMail" New topic

Problem regarding JavaMail

Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi All,
I am trying to write a simple Java application to send a mail using java mail api. I want to use my computer as an smtp host.

The code is as under :

I am getting the following exception :

javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1611)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1369)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at com.javamail.example.SMTPClient$SendAction$1.run(SMTPClient.java:102)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:110)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:88)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1589)
... 9 more

Please help me as i am unable to solve the problem. Thanks in advance.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42645
Are you running a mail server on this machine? Without one you can't send mail. If you don't have one yet, Apache James is a open source Java mail server you could use.

Ping & DNS - my free Android networking tools app
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi Ulf,
I have now installed Apache James. Now when I run my program nothing comes, no error , no exception and the mail also dosen't come . Please Help me
Paul Clapham

Joined: Oct 14, 2005
Posts: 18910

When you use JavaMail to send an e-mail, and you don't get any exceptions but the e-mail doesn't arrive, the next step is to ask the administrator of the SMTP server to investigate.

In this case, that administrator is you. You will have to see what logging James does. It's quite possible you have configured it incorrectly. It might not have a connection to the Internet, or you might have set it up in such a way that other servers won't talk to it. Anything is possible. I recall that it comes with how-to documentation but it's a few years since I looked at it.

If you don't want to become an administrator, perhaps you should find another server you can use. Then you can ask its administrator to deal with this sort of problem.
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
I am connected to the internet when I run my mail program. When I setup the account with Mozilla Thunderbird then its working and I am able to send and receive mails. One important thing when I am trying to send mail to my gmail account or yahoo account using Thunderbird then also the mail dosen't go. Why is this happening ?. But I am not able to do the same thing using my SMTP client program. I am not able to understand where I am going wrong.
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
Hi All,
Following is the log which I am getting in apache james mail server.



Please Help me and guide me where I am going wrong.
Thanks in advance.
It is sorta covered in the JavaRanch Style Guide.
subject: Problem regarding JavaMail