Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Mail

 
Mehul Kumbhani
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try to telnet the SMTP server at port 25?
 
Mehul Kumbhani
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No I am using netbeans and java mail API.
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you gime us a example code or site which shows how to send email using java?
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about the JavaEnterpriseEditionFaq?
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20756
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic