javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/calendar;method=REQUEST

Viewed 1288

I am trying send calendar meeting invite using java mail. But am facing below error. i have searched on stack overflow. All answers with related error are for mail.

no object DCH for MIME type text/calendar;method=REQUEST

code :

BodyPart calendarPart = new MimeBodyPart();
calendarPart.addHeader("Content-Class", "urn:content-classes:calendarmessage");
calendarPart.setContent(calendarContent, "text/calendar;method=REQUEST");

Multipart multipart = new MimeMultipart();
multipart.addBodyPart(calendarPart);

MimeMessage message = new MimeMessage(session);
message.addHeaderLine("method=REQUEST");
message.addHeaderLine("charset=UTF-8");
message.addHeaderLine("component=VEVENT");
message.setSubject(meetingSubject);
message.setContent(multipart);

Transport.send(message);

Error Trace:

  Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/calendar;method=REQUEST 
 at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:885) 
 at javax.activation.DataHandler.writeTo(DataHandler.java:316) 
 at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1485) 
 at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:865) 
 at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:462) 
 at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:103) 
 at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:883) 
 at javax.activation.DataHandler.writeTo(DataHandler.java:316) 
 at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1485) 
 at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1773) 
 at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1121) 
3 Answers

The issue got resolved. Update Mail to 1.4.7. Also, there were some issues on the server-side related to the Amazon SES service.

The problem is that there's no class configured that knows how to convert a calendarContent object (whatever that is) to a byte stream in the format of the MIME type text/calendar. If you can do that conversion yourself, by converting the object to a byte array or a String, then JavaMail can handle it without further configuration. If you want to configure the system to be able to do that conversion for you, you'll need to configure the JavaBeans Activation Framework, and you'll need to supply a class that does the conversion. Since you're only doing this yourself and not trying to make it easy for others, the simplest approach is what I described first - convert the calendarContent object to a byte array/stream or a String.

I faced the same problem a few days ago, and just today I found a solution that solved 100% my problem.

JavaMail depends on some configuration files to map MIME types to Java classes (e.g., multipart/mixed to javax.mail.internet.MimeMultipart). These configuration files are loaded using the ClassLoader for the application. If the ClassLoader doesn't function properly (in my case due to dependency conflicts), these configuration files won't be found.

Just add the following code to the beggining of your method:

final MimetypesFileTypeMap mimetypes = (MimetypesFileTypeMap) MimetypesFileTypeMap.getDefaultFileTypeMap();
mimetypes.addMimeTypes("text/calendar ics ICS");
final MailcapCommandMap mailcap = (MailcapCommandMap) MailcapCommandMap.getDefaultCommandMap();
mailcap.addMailcap("text/calendar;; x-java-content-handler=com.sun.mail.handlers.text_plain");

I hope it is not too late and that it can help you all.

Related