JavaMail - replying to a Multipart message and including the original contents
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Todd_Gould
Posted On:   Saturday, May 10, 2003 08:46 PM

Hello: I'm relatively new to JavaMail and am trying to build a reply message to a Multipart message that includes the original Multipart unaltered as well as an additional new part containing simple plain/text (the reply message). Here are the steps I am taking: // In the following, email is a JavaMail wrapper class I use and msgNum is the // number of the message in the INBOX that I am replying to. Message msg = email.getMessage( msgNum ).reply( false); // build empty reply // I've verified that msg is a Multipart via isMimeType( "multipart/*" ) msg.setRecipients( .... ); msg.setFrom( .... ); msg.setReplyTo( ... ); m   More>>

Hello:

I'm relatively new to JavaMail and am trying to build a reply message
to a Multipart message that includes the original Multipart unaltered
as well as an additional new part containing simple plain/text (the
reply message). Here are the steps I am taking:

// In the following, email is a JavaMail wrapper class I use and
msgNum is the
// number of the message in the INBOX that I am replying to.
Message msg = email.getMessage( msgNum ).reply( false); // build
empty reply
// I've verified that msg is a Multipart via isMimeType( "multipart/*"
)

msg.setRecipients( .... );
msg.setFrom( .... );
msg.setReplyTo( ... );
msg.setSubject( .... );

Multipart mp = (Multipart) email.getMessage( msgNum ).getContent();
// Create and add new text/plain part
MimeBodyPart bp = new MimeBodyPart();
bp.setContent( request.getParameter( "note" ), // comes from a
servlet form
"text/plain" );
mp.addBodyPart( bp, 0 ); // Add text as new first

msg.setContent( mp ); // Adjust reply msg with modified Multipart
contents

msg.saveChanges();

Transport.send( msg );

This all seems to work just fin right up until the Transport.send( msg
) call which fails with the following exception:

Caught exception while sending: javax.mail.SendFailedException:
Sending failed; nested exception is: javax.mail.MessagingException:
IOException while sending message; nested exception is:
java.io.IOException: javax.mail.MessagingException: No inputstream
from datasource

I'm sure I am missing something simple or doing something wrong. I'd
appreciate any help that you can privide.

Thanks in advance.

   <<Less

Re: JavaMail - replying to a Multipart message and including the original contents

Posted By:   navkalp_varshney  
Posted On:   Monday, May 12, 2003 05:46 AM

It seems to me that u should add something like this to your code.


MimeBodyPart mbp2 = null;
File fileToSend = new File(filepath);
if ( fileToSend.exists() && fileToSend.canRead() )
{
mbp2 = new MimeBodyPart();
mbp2.setDataHandler( new DataHandler( new FileDataSource( fileToSend ) ) );
mbp2.setFileName( filename );
mp.addBodyPart( mbp2 );
msg.setContent( mp );
}



Hope this will help you,
About | Sitemap | Contact