U have to set the class path of two jar files Mail.jar,Activation.jar


import javax.mail.*;
import javax.mail.internet.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class MySendMail extends HttpServlet {

private String smtpHost;

// smtpHost is used for storing hostname of the SMTP server

public void init(ServletConfig config) throws ServletException {
super.init(config);

smtpHost = "203.200.51.3";
/* use your mail server name or ip-address */
}

public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException, java.io.IOException {
String from = req.getParameter("from");
String to = req.getParameter("to");
String cc = req.getParameter("cc");
String subj = req.getParameter("subject");
String txt = req.getParameter("text");

String status;

try {

java.util.Properties properties = System.getProperties();
properties.put("mail.smtp.host", smtpHost);
Session session = Session.getInstance(properties, null);
// Construct the message
MimeMessage msg = new MimeMessage(session);

// For Setting the from address
Address frmAddress = new InternetAddress(from);
msg.setFrom(frmAddress);
// Parse and set the recipient addresses
Address[] toAddresses = InternetAddress.parse(to);

msg.setRecipients(Message.RecipientType.TO,toAddresses);
Address[] ccAddresses = InternetAddress.parse(cc);
msg.setRecipients(Message.RecipientType.CC,ccAddresses);

// Set the subject and text
msg.setSubject(subj);
msg.setText(txt);
Transport.send(msg);
status = "Your message was sent.";
}
catch (AddressException e) {
status = "There was an error parsing the addresses.";
}
catch (SendFailedException e) {
status = "There was an error sending the message.";
}
catch (MessagingException e) {
status = "There was an unexpected error.";
}

// Output a status message
res.setContentType("text/html");
java.io.PrintWriter writer = res.getWriter();
writer.println("<html><head><title>Status</title></head>");
writer.println("<body><p>"+ status +"</p></body></html>" );
writer.close();
}
}