aspose file tools
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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply 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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Not able to send mail using Servlet and JSP
 
Similar Threads
how to send email from java program
Confusion in JavaMail
Enable Mailing services
Can not send mail to other mail server
Java Mail Authentication