javax.activation.UnsupportedDataTypeException: no object DCH for MIME type
843830Nov 28 2003 — edited Nov 28 2003Hi,
Ever since trying to attach files to HTML e-mails I have had this problem. (See at the bottom)
I've just checked my mailcap file and this seems fine to me??? Or at least it is according to http://www.jguru.com/faq/view.jsp?EID=237257. The contents of my mailcap file is below.
Why does the error keep occuring? I am using Tomcat 4.1.27 with JavaMail to try and send the e-mails.
Thanks,
Stuart Stephen
-------------------------------
#
# @(#)mailcap 1.5 00/09/26
#
# Default mailcap file for the JavaMail System.
#
# JavaMail content-handlers:
#
text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain
text/html;; x-java-content-handler=com.sun.mail.handlers.text_html
text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml
multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed
message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822
-------------------------------
My email sending code is below:
private static boolean sendMessage(String[] to, String subject, String message, String from, String[] filelocation) {
try {
String recievers = StringWizard.arrayToText(to, ", ");
ContentType ct = new ContentType("text/plain", "iso-8859-1", new ParameterList());
StringBuffer msg = new StringBuffer(message);
Properties prop = new Properties();
prop.put("mail.smtp.auth", "true");
prop.put("mail.transport.protocol", "smtp");
prop.put("mail.smtp.host", MAIL_HOST);
Session mail_Session=Session.getInstance(prop, null);
InternetAddress fromAddress = new InternetAddress(from);
InternetAddress toAddress[] = new InternetAddress[to.length];
for(int i=0;i<to.length;i++) toAddress[i] = new InternetAddress(to);
InternetAddress[] reply = { fromAddress };
MimeMessage myMessage = new MimeMessage(mail_Session);
myMessage.setFrom(fromAddress);
myMessage.setReplyTo(reply);
for(int i=0;i<to.length;i++) myMessage.addRecipient(Message.RecipientType.TO, toAddress[i]);
myMessage.setSentDate(new java.util.Date());
myMessage.setSubject(subject);
Multipart mp = new MimeMultipart();
// add default stuff (text).
// add text.
MimeBodyPart textpart = new MimeBodyPart();
textpart.setText(msg.toString());
mp.addBodyPart(textpart);
// add html.
boolean sendHTML = UserHelper.HTMLEmails(to[0]);
if(sendHTML) {
MimeBodyPart htmlpart = new MimeBodyPart();
htmlpart.setContent(StringWizard.stripJavascript(StringWizard.toHTML(msg.toString())), "text/html" + " (" + msg.length() + " chars)");
mp.addBodyPart(htmlpart);
}
// if we are sending any files with this email add them.
boolean attached = false;
if(filelocation!=null && filelocation.length>0) {
for(int i=0;i<filelocation.length;i++) {
File attachment = new File(filelocation[i]);
if(attachment.exists() && attachment.isFile() && attachment.canRead()) {
System.err.println("Email.sendMessage() : Attaching file " + attachment.getAbsolutePath() + " to email bound for " + recievers);
MimeBodyPart attachfile = new MimeBodyPart();
FileDataSource fds = new FileDataSource(attachment);
DataHandler dh = new DataHandler(fds);
attachfile.setFileName(attachment.getName());
attachfile.setDisposition(Part.ATTACHMENT);
attachfile.setDescription("Attached File: " + attachment.getName());
attachfile.setDataHandler(dh);
mp.addBodyPart(attachfile);
attached = true;
}
}
}
if(attached==false && !sendHTML)myMessage = addMessageHeaders(myMessage, ct);
myMessage.setContent(mp);
Transport tr = mail_Session.getTransport("smtp");
tr.connect(MAIL_HOST, USERNAME, PASSWORD);
myMessage.saveChanges();
tr.sendMessage(myMessage, toAddress);
tr.close();
return true;
}
catch(Exception e){
e.printStackTrace(System.err);
return false;
}
}
The error I am getting is:
javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type
text/html (844 chars)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:353)
at com.t2ut.email.Email.sendMessage(Email.java:246)
at com.t2ut.email.Email.sendMail(Email.java:50)
at org.apache.jsp.tcr_update_list_jsp._jspService(tcr_update_list_jsp.java:157)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:575)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:498)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:822)
at org.apache.jsp.tcr_view_jsp._jspService(tcr_view_jsp.java:76)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:575)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:498)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:822)
at org.apache.jsp.tcr_jsp._jspService(tcr_jsp.java:98)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.AccessLogValve.invokeAccessLogValve.java:509)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.ajp.tomcat4.Ajp13Processor.process(Ajp13Processor.java:466)
at org.apache.ajp.tomcat4.Ajp13Processor.run(Ajp13Processor.java:585)
at java.lang.Thread.run(Thread.java:484)