permaculture playing cards*
The moose likes Sockets and Internet Protocols and the fly likes Java Mail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Java Mail" Watch "Java Mail" New topic
Author

Java Mail

Mehul Kumbhani
Greenhorn

Joined: Apr 24, 2010
Posts: 9
I have code to send Mail from My web application.

I get the following error.

Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:284)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:227)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1672)
... 38 more

INFO: Exception javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
Muthukrishnan Manoharan
Ranch Hand

Joined: Aug 27, 2008
Posts: 91

Did you try to telnet the SMTP server at port 25?
Mehul Kumbhani
Greenhorn

Joined: Apr 24, 2010
Posts: 9
No I am using netbeans and java mail API.
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Mehul Kumbhani wrote:No I am using netbeans and java mail API.

Actually, I think that was a suggestion that you try telnet.

Many ISPs don't allow machines connected to their network to make an outgoing TCP connection on port 25 as a spam reduction effort.
Mehul Kumbhani
Greenhorn

Joined: Apr 24, 2010
Posts: 9
Thanks for your kindly reply,
But sir i hava not knowledge of how to use telnet from java and netbeans,

can you suggest me.
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Mehul Kumbhani wrote:Thanks for your kindly reply,
But sir i hava not knowledge of how to use telnet from java and netbeans,

can you suggest me.

No, telnet is a utility application that comes with most operating systems. Assuming you're using Windows, go to Start -> Run, then enter telnet.exe smtp.gmail.com 25 and hit return. If you get a hello message from the SMTP server, then you are ale to connect. To get out, just type quit and hit return.
If, however, it hangs or gives you a connection refused error, then you are not able to connect.
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
can you gime us a example code or site which shows how to send email using java?
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
How about the JavaEnterpriseEditionFaq?
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
I'm thinking that the telnet suggestion was not clear to the original poster, so I would like to elaborate just a bit.
The point is to debug the problem and see if the issue is with your use of the JavaMail API, or if you have a general TCP/IP connectivity issue.

The telnet application can be used to see if you are able to connect to the host/port via TCP/IP. If this doesn't work, no API which uses TCP/IP (such as Java Mail) will work either. No sense debugging Java Mail if you cannot get TCP/IP connectivity working.

I hope this make it clearer.

Were you able to connect to the GMail SMTP server host using telnet?

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Mark E Hansen wrote:Were you able to connect to the GMail SMTP server host using telnet?

The answer to that question is going to be "no". Gmail doesn't use unsecured e-mail connections so it won't be listening at port 25.

And if you follow the JavaEnterpriseEditionFaq link and search for "gmail" you will find a link to what the JavaMail FAQ itself has to say about Gmail. Unfortunately, if you don't understand how e-mail works and how TCP/IP networking works, you're going to have a lot of trouble making your e-mail programs work when you have networking problems. As Mark said, no amount of looking at the code is going to help if the configuration isn't right.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java Mail