Java mail - Failed to connect to host
I am trying to submit a Java electronic application by following the tutorial http://www.tutorialspoint.com/java/java_sending_email.htm
When I try to run it, copypasted the first code from the link above, I get an error that it cannot connect to the host which is localhost. Here is the output when I ping localhost:
Pinging Home-PC [::1] with 32 bytes of data: Reply from ::1: time<1ms Reply from ::1: time<1ms Reply from ::1: time<1ms Reply from ::1: time<1ms
Since I am very inexperienced in communications, I do not know what went wrong, and again, I need help. So the problem is that my localhost is not configured properly or is there something wrong with my code? What can I do?
I am using Tomcat v8.0 server.
I also add console output:
Couldn't connect to host, port: localhost, 25; timeout -1; nested exception is: at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2054) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697) at javax.mail.Service.connect(Service.java:364) at javax.mail.Service.connect(Service.java:245) at javax.mail.Service.connect(Service.java:194) at javax.mail.Transport.send0(Transport.java:253) at javax.mail.Transport.send(Transport.java:124) at test.Test.main(Test.java:51) Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at java.net.Socket.connect(Socket.java:538) at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:329) at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2020) 7 more:
source to share
I am assuming you do not have the
-Server installed on your local machine. For testing purposes, run FakeSMTP . If it is up and running, programs can connect and drop mail.
Here is the result when I ping localhost
It only shows what the server is responding to
. This does not mean that the server is running an SMTP service, nor does it mean that the server is not responding, that the server is down - sometimes administrators block it
telnet $server 25
allows you to connect to a mail server.
Reason: java.net.ConnectException: Connection refused: connect
This indicates that the Service is inactive because the port is closed.
source to share