when i tried to send an email to an account it does not sent. the error result will be displayed. i got an error in the apache tomcat bin log like this:
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port:25;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
at com.sun.mail.smtp.SmtpTransport.protocolConnect(SMTPTransport.java:638)

at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.jsp.mailer_jsp._jspService(mailer_jsp.java:87)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)


caused by: java.net.ConnectException: Connection refuse: connect
at java.net.TwoStacksPlainSocketImpl.socketConect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:288)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1990)
... 27 more

What is the solution of this error.? i need your help buddies..

<%@ page import="java.io.*,java.util.*,javax.mail.*"%>
<%@ page import="javax.mail.internet.*,javax.activation.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
   String result;
   // Recipient's email ID needs to be mentioned.
   String to = request.getParameter("to");

   // Sender's email ID needs to be mentioned
   String from = request.getParameter("from");

   String host = "smtp.mail.yahoo.com";

   // Get system properties object
   Properties properties = System.getProperties();

   // Setup mail server
   properties.setProperty("mail.smtp.host", host);

   // Get the default Session object.
   Session mailSession = Session.getDefaultInstance(properties);

      // Create a default MimeMessage object.
      MimeMessage message = new MimeMessage(mailSession);
      // Set From: header field of the header.
      message.setFrom(new InternetAddress(from));
      // Set To: header field of the header.
                               new InternetAddress(to));
      // Set Subject: header field
      message.setSubject("This is the Subject Line!");
      // Send the actual HTML message, as big as you like
      message.setContent("<h1>This is actual message</h1>",
                            "text/html" );
      // Send message
      result = "Sent message successfully....";
   }catch (MessagingException mex) {
      result = "Error: unable to send message....";
<title>Send HTML Email using JSP</title>
<h1>Send Email using JSP</h1>
<p align="center">
   out.println("Result: " + result + "\n");

that is the code.. what is the problem with the code?