File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Not able to send mail using Servlet and JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Not able to send mail using Servlet and JSP" Watch "Not able to send mail using Servlet and JSP" New topic

Not able to send mail using Servlet and JSP

Nandan Jain
Ranch Hand

Joined: Feb 14, 2006
Posts: 44
For a small application I am using Servlet and JSP. In one servlet I am calling sendMail() funcation which should send mail to user..but here it causes problem. This sendMail() function works well when I use inside main() funcation in java file. But It starts creating problem in JSP and servlet.
following is the code inside the sendMail()function.
String host = "";
Properties props = new Properties();
props.put("", host);
props.put("mail.debug", "true");
Session session = Session.getInstance(props);
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Test E-Mail through Java");
msg.setSentDate(new Date());
msg.setText("This is a test of sending a " +
"plain text e-mail through Java.\n" +
"Here is line 2.");
}catch (MessagingException mex) {


And following exception I am getting..
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/plain; charset=
at javax.activation.ObjectDataContentHandler.writeTo(
at javax.activation.DataHandler.writeTo(
at javax.mail.internet.MimeBodyPart.writeTo(
at javax.mail.internet.MimeMessage.writeTo(
at com.sun.mail.smtp.SMTPTransport.sendMessage(
at javax.mail.Transport.send0(

... 18 more

I dont understand what is this ...pls help.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Have you verified that all the jar files on your classpath are available to the web app?
If it's working in a command line app but not from a servlet, I'm guessing that you might have a different version of one of the libs (jar files) in your container.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Not able to send mail using Servlet and JSP
It's not a secret anymore!