wood burning stoves*
The moose likes EJB and other Java EE Technologies and the fly likes Javamail Exception (gnu.mail.handler.TextHtml) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Javamail Exception (gnu.mail.handler.TextHtml)" Watch "Javamail Exception (gnu.mail.handler.TextHtml)" New topic
Author

Javamail Exception (gnu.mail.handler.TextHtml)

Live Altius
Greenhorn

Joined: Aug 31, 2008
Posts: 1
Hi,
In my web application I'm trying to send a HTML mail with Javamail 1.4
With my machine(Win Xp, tomcat 5, jdk 1.5) it's working fine but when I deployed same application
on server (Cent OS 5, tomcat 5, jdk 1.5) I'm getting exception.
The function I've written to send HTML mail is as follows:

public boolean sendMail(String from, String password, String to, String fileName)
{
Properties props = System.getProperties();
props.put("mail.smtp.host", "mail.gmail.com");
props.put( "mail.smtp.auth", "true" );
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.quitwait", "false");

Authenticator auth = new SmtpAuthenticator(from,password);
Session session = Session.getInstance(props,auth);
session.setDebug(debug);

try {
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);

msg.setSubject(subject);
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(txtMsg, "text/html");
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.attachFile(fileName);

Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);

msg.setContent(mp);

msg.setSentDate(new Date());
Transport.send(msg);

return true;

} catch (MessagingException mex) {
errMsg= mex.toString();
mex.printStackTrace();
Exception ex = null;
if ((ex = mex.getNextException()) != null)
ex.printStackTrace();
return false;
} catch (Exception ex) {
ex.printStackTrace();
errMsg= ex.toString();
return false;
}
}



With this code I'm getting following following error on Server (Cent OS 5)

DEBUG: setDebug: JavaMail version 1.4.1
java.lang.ClassCastException: gnu.mail.handler.TextHtml
at javax.activation.MailcapCommandMap.getDataContentHandler(MailcapCommandMap.java:609)
at javax.activation.MailcapCommandMap.createDataContentHandler(MailcapCommandMap.java:563)
at javax.activation.DataHandler.getDataContentHandler(DataHandler.java:625)
at javax.activation.DataHandler.writeTo(DataHandler.java:329)
at javax.mail.internet.MimeUtility.getEncoding(MimeUtility.java:261)
at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1321)
at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2074)
at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:2042)
at javax.mail.Transport.send(Transport.java:117)
at sm.email.EmailSender.sendMail(EmailSender.java:149)
at sm.classifieds.RegStepOne.processRequest(RegStepOne.java:109)
at sm.classifieds.RegStepOne.doPost(RegStepOne.java:255)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:595)

Please help me out, Thanks..
[ August 31, 2008: Message edited by: Live Altius ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javamail Exception (gnu.mail.handler.TextHtml)
 
Similar Threads
Problem with Sending Mail
Sending mail through Exchange Server
Attaching files using Java Mail API
Sending Email in java through MS Exchange Server