Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Not able to send mail using Servlet and JSP  RSS feed

Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!