title: Java mail - Couldn't connect to host
body: <p>I am trying to send an email Java application, following guide on <a href="http://www.tutorialspoint.com/java/java_sending_email.htm" rel="nofollow">http://www.tutorialspoint.com/java/java_sending_email.htm</a></p>
  
  <p>When I try to run it, copypasted first code from link above, I get an error that it could not connect to host, which is a localhost. Here is a result when I ping localhost:</p>
  
  <pre><code>Pinging Home-PC [::1] with 32 bytes of data:
  Reply from ::1: time&lt;1ms
  Reply from ::1: time&lt;1ms
  Reply from ::1: time&lt;1ms
  Reply from ::1: time&lt;1ms
  </code></pre>
  
  <p>Since I am greatly inexperienced in communications, I do not know what went wrong, and yet again, I need help. So, is the issue in my localhost not being properly configured, or is something wrong with my code? What could I do?</p>
  
  <p>I am using Tomcat v8.0 server.</p>
  
  <p>I am also adding console output:</p>
  
  <pre><code>com.sun.mail.util.MailConnectException: 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
  </code></pre>