This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Author

Not able to send mail using Servlet and JSP

Nandan Jain
Ranch Hand

Joined: Feb 14, 2006
Posts: 44
Hi,
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 = "mail.etn.com";
Properties props = new Properties();
props.put("mail.smtp.host", 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.");
Transport.send(msg);
}catch (MessagingException mex) {
mex.printStackTrace();
}

-------------------------------------------------------

And following exception I am getting..
=======================================================
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/plain; charset=
us-ascii
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:885)
at javax.activation.DataHandler.writeTo(DataHandler.java:316)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1350)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1683)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:585)
at javax.mail.Transport.send0(Transport.java:169)

... 18 more
=======================================================

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

Regards,
Nandan.
Ben Souther
Sheriff

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Not able to send mail using Servlet and JSP
 
Similar Threads
Can not send mail to other mail server
Enable Mailing services
Confusion in JavaMail
Java Mail Authentication
how to send email from java program