Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 29th, 2006, 12:08 AM
Authorized User
Join Date: Aug 2005
Location: , , .
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Default some serious problem

i got this code from a site ... it is compiled successfully but gives an exception "java.net.UnknownHostException: mailhost"
does it mean that i need a Mail Server to execute this code? ... if YES, then where i can find a mail server, plz give me a web link ... if NO, then what iz the problem with this code ... plz guide me bcoz i m new in this field

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import com.oreilly.servlet.ParameterParser;
import com.oreilly.servlet.ServletUtils;

import sun.net.smtp.SmtpClient;

public class MailServlet extends HttpServlet {

  static final String FROM = "kan@ban.kbn";
  static final String TO = "kanoorani@hotmail.com";

  public void doGet(HttpServletRequest req, HttpServletResponse res)
                               throws ServletException, IOException {
    PrintWriter out = res.getWriter();

    ParameterParser parser = new ParameterParser(req);
    String from = parser.getStringParameter("from", FROM);
    String to = parser.getStringParameter("to", TO);

    try {
      SmtpClient smtp = new SmtpClient(); // assume localhost
      PrintStream msg = smtp.startMessage();

      msg.println("To: " + to); // so mailers will display the To: address
      msg.println("Subject: just checking...");

      Enumeration enm = req.getParameterNames();
      while (enm.hasMoreElements()) {
        String name = (String)enm.nextElement();
        if (name.equals("to") || name.equals("from")) continue; // Skip to/from
        String value = parser.getStringParameter(name, null);
        msg.println(name + " = " + value);

      msg.println("Sent by " + HttpUtils.getRequestURL(req));


      out.println("Thanks for the submission...");
    catch (Exception e) {
      out.println("There was a problem handling the submission...");
      getServletContext().log(e, "There was a problem sending email");

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

All times are GMT -4. The time now is 01:44 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.