UnsupportedDataTypeException:
I am getting the following message when I attempt to send an email with an image that i am attempting to convert to png
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type image/png
I set content with the following statement
mbp1.setContent(ActReport.EmailSetup(), "image/png");
ActReport.EmailSetup () returns a BufferedImage.
I am executing the program from NetBeans IDE 4.0. The activation jar file is in my ext directory. Does anyone have any ideas.
# 1
JavaMail doesn't have builtin knowledge of how to convert an Image
object to a MIME image/png byte stream. If you want to teach it how
to do that, you can write your own DataContentHandler (DCH).
A simpler approach is to do the conversion in your program and then
use a ByteArrayDataSource. See the JavaMail FAQ.
# 3
I think there's more confusion or misunderstanding in your question,
but, to get you started...
There are various Java image APIs that allow you to write an Image
object to a file or convert it to a byte array in a particular format. Common
formats are GIF and JPEG. Given a byte array or byte stream in one of
these formats, you would use MIME types image/gif or image/jpeg.
All that's sent in the message is the raw bytes, along with the MIME type.
That's all the receiver needs to interpret the image.
If the image is intended to be used in combination with other data in
your message, you probably want to create a multipart/related message.
# 4
I am attempting to use the non canonicle case specified in the JavaBeans activation specification where I have an image in memory and am attempting to use instruction
ByteArrayDataSource(byte[] data, String type)
How do I get from a JPanel stored in memory to a byte[]. I would assume that String type would be some sort of image/?. I have been trying to use some sort of png conversion but have not figured out given the fact that I do not wish to use a file how to do this. Could you give me more detailed recommendation.I would b very appreciative.
# 5
I'm not an expert in the java.awt.image APIs, and this is the wrong forum to ask.
I spent a few minutes searching and found these links, which should help:
http://java.sun.com/j2se/1.4.2/docs/guide/imageio/spec/apps.fm4.html
http://java.sun.com/developer/technicalArticles/Media/AdvancedImage/
Write the image to a ByteArrayOutputStream, get the bytes, and give them
to the ByteArrayDataSource.