aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Email Java object in memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Email Java object in memory" Watch "Email Java object in memory" New topic
Author

Email Java object in memory

Chris Wang
Ranch Hand

Joined: Jan 13, 2004
Posts: 34
Hi,

I got an exception:
javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type audio/x-wav
at com.sun.mail.smtp.SMTPTransport.sendMessage
...
when I tried to email a java object "InputStream" as an attachment.
The code segment is as follows:

Multipart multipart = new MimeMultipart();
try
{
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("");
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
//leave_message_InputStream is of java.io.InputStream
DataHandler dh = new DataHandler(leave_message_InputStream, "audio/x-wav");
messageBodyPart.setDataHandler(dh);
messageBodyPart.setFileName(recordingFileName_show);
multipart.addBodyPart(messageBodyPart);
}
catch (MessagingException mex)
{
mex.printStackTrace();
}
//Here I send the email ...

In TOMCAT/common/lib I put the lastest mail.jar(JavaMail 1.4) and activation.jar(JavaBean Activation Framework 1.1).

If I save leave_message_InputStream to a file and then use the file as the Datasource of DataHandler, the updated code listing below worked fine:

final URL url = new URL(url of the file);
DataSource source = new URLDataSource(url);
DataHandler dh = new DataHandler(source);

For performance consideration, I don't need to save the java object to a file and then read it and delete it.

Any help is appreciated!

Chris
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18115
    
    8

Since you have JavaMail 1.4, you could use a javax.mail.util.ByteArrayDataSource based on that input stream.
Chris Wang
Ranch Hand

Joined: Jan 13, 2004
Posts: 34
Hi,
When I changed the code to:
javax.mail.util.ByteArrayDataSource bds =
new javax.mail.util.ByteArrayDataSource(leave_message_InputStream, "audio/x-wav");
DataHandler dh = new DataHandler(bds);
The excption was gone. But bds object is empty, no audio data.
leave_message_InputStream is of com.oreilly.servlet.multipart.PartInputStream and has audio data inside.

Could you please show me the code how to use leave_message_InputStream to build ByteArrayDataSource object?

Thanks,

Chris
Chris Wang
Ranch Hand

Joined: Jan 13, 2004
Posts: 34
Hi,

The problem is fixed. Just want to share the idea here.
The leave_message_inputStream has been read previously and can NOT "rewind", so when I tried to construct the new ByteArrayDataSource usng leave_message_inputStream, bds is empty.

Chris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Email Java object in memory
 
Similar Threads
Multiple Attachment
How To Send Multiple Attachments In An Email
how to send mail using gmail server
Unable to send mail via Web Service
java mail attachment notification