HELP!! no object DCM for MIME type text/html error

I hope someone can help me please. I keep getting the following error whenever I try and send a mail. I don't understand why as the same code functions perfectly in my dev environment(JBuilder 4), but under Tomcat 3.2.1 it throws this.

I have got both the mail.jar and activation.jar in my classpath.

Is this something to do with Tomcat?

javax.servlet.ServletException: Sending failed;

nested exception is:

javax.mail.MessagingException: IOException while sending message;

nested exception is:

javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/html

at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)

at marketing._0002fmarketing_0002fkermitMail_0002ejspkermitMail_jsp_0._jspService(_0002fmarketing_0002fkermitMail_0002ejspkermitMail_jsp_0.java:200)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)

at org.apache.tomcat.core.Handler.service(Handler.java:286)

at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)

at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)

at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)

at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)

at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)

at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)

at java.lang.Thread.run(Thread.java:484)

Any help much appreciated!!!

[2122 byte] By [richardsimmonds] at [2007-9-26 1:59:16]
# 1

Try this ..... I hope it will solve your prblm.

msg.setDataHandler(new DataHandler(new

ByteArrayDataSource(texto.toString(), "text/html")));

msg.setText("Your mail msg");

Message msg = new MimeMessage(sesion);

msg.setFrom(new InternetAddress("from address"));

msg.setRecipients(Message.RecipientType.TO,

InternetAddress.parse("toaddress", false));

msg.setSubject("Your subject");

msg.setDataHandler(new DataHandler(new

ByteArrayDataSource(texto.toString(), "text/html")));

msg.setText("Your mail msg");

// Send message

Transport.send(msg);

Tomy

tomym at 2007-6-29 3:18:11 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Cheers. I was using setContent() instead of the lower level setDataHandler(). Even though they should both work!!All fine now though :-)
richardsimmonds at 2007-6-29 3:18:11 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
texto is missing.....
bongortiz at 2007-6-29 3:18:11 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

FYI...

Got the same error, and the solution worked (thanks!). But I noticed the 'ByteArrayDataSource' class does not come pre-packaged in the JavaMail, Activation (JAF), or my iPlanet JAR files. However, I found it included in the JavaMail example folder. Once I compiled and included it in my classpath, the JSP worked.

Here is the ByteArrayDataSource.java source if anybody needs it:

BEGIN source code

// package yourpackage;

import java.io.*;

import javax.activation.*;

public class ByteArrayDataSource implements DataSource {

private byte[] data;// data

private String type;// content-type

/* Create a DataSource from an input stream */

public ByteArrayDataSource(InputStream is, String type) {

this.type = type;

try {

ByteArrayOutputStream os = new ByteArrayOutputStream();

int ch;

while ((ch = is.read()) != -1)

os.write(ch);

data = os.toByteArray();

} catch (IOException ioex) { }

}

/* Create a DataSource from a byte array */

public ByteArrayDataSource(byte[] data, String type) {

this.data = data;

this.type = type;

}

/* Create a DataSource from a String */

public ByteArrayDataSource(String data, String type) {

try {

// Assumption that the string contains only ASCII

// characters! Otherwise just pass a charset into this

// constructor and use it in getBytes()

this.data = data.getBytes("iso-8859-1");

} catch (UnsupportedEncodingException uex) { }

this.type = type;

}

public InputStream getInputStream() throws IOException {

if (data == null)

throw new IOException("no data");

return new ByteArrayInputStream(data);

}

public OutputStream getOutputStream() throws IOException {

throw new IOException("cannot do this");

}

public String getContentType() {

return type;

}

public String getName() {

return "dummy";

}

}

END sourcecode

samsarullo at 2007-6-29 3:18:11 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

I've meet the same problem using mail.jar and activation.jar.

This error means that no DataContentHandler class has been found when you want to send a mail.

When you set the content type of your message ( "text/plain" for example), the Transport instance try to found a class that is able to write your message as a text/plain.

One solution is to define a DataContentHandlerFactory that returns the rigth DataContentHandler object according the content type :

For example :

package com.misys.util.mail;

import javax.activation.DataContentHandlerFactory;

import javax.activation.DataContentHandler;

import com.sun.mail.handlers.*;

/**

* Titre :Apollo Mail

* Description :

* @author Nicolas Estienne

* @version 1.0

*/

public class UtlMailContentFactory implements DataContentHandlerFactory {

public UtlMailContentFactory() {

}

public DataContentHandler createDataContentHandler( String parm1 ) {

if( parm1.equalsIgnoreCase( "text/plain") )

return new com.sun.mail.handlers.text_plain();

else if ( parm1.equalsIgnoreCase( "text/html" ) )

return new com.sun.mail.handlers.text_html();

else

return null;

}

}

In the source code of your application, adds the following line :

DataHandler.setDataContentHandlerFactory( new UtlMailContentFactory() );

It works well.

Nicolas

nestienn at 2007-6-29 3:18:11 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6
I had the similar problem. But when I upgraded my mail.jar the problem has gone.
jevi_rk at 2007-6-29 3:18:11 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7
weeeeeeeeeeee, thanks a lot, i applied bot solution and it worked (but ONLY with both solucion) thanks a lot!.
tengoku at 2007-6-29 3:18:11 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8
Thanks. It works. P.S: "Texto" is the email's body
lenin2k at 2007-6-29 3:18:11 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9
hi i tried your solution but it sends the msessage in text format where as i have to send html format mail
Ashitosh at 2007-6-29 3:18:11 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 10
Soory I got it Cheers its working fineThanks to All
Ashitosh at 2007-6-29 3:18:11 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...