MimeMessage.writeTo() a stream and new MimeMessage(sess, stream) dont work good. Multiparts are lost. Why?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   joro_simeonov
Posted On:   Friday, January 24, 2003 03:42 AM

here is the code import javax.mail.internet.*; import javax.mail.*; import javax.activation.*; import java.io.*; public class In_Out_Test { public static void main(String[] AS) throws Exception { MimeMultipart messageMultipart = new MimeMultipart(); MimeBodyPart bodyPart1 = new MimeBodyPart(); bodyPart1.setContent("AAAA", "text/plain"); messageMultipart.addBodyPart(bodyPart1); MimeBodyPart bodyPart2 = new MimeBodyPart(); bodyPart2.setContent("BBB", "text/plain"); messageMultipart.addBodyPart(bodyPart2); Session session = Session.getDefaultInstance(System.getProperties(), null); Mi   More>>

here is the code

			
import javax.mail.internet.*;
import javax.mail.*;
import javax.activation.*;
import java.io.*;

public class In_Out_Test {
public static void main(String[] AS) throws Exception {
MimeMultipart messageMultipart = new MimeMultipart();

MimeBodyPart bodyPart1 = new MimeBodyPart();
bodyPart1.setContent("AAAA", "text/plain");
messageMultipart.addBodyPart(bodyPart1);
MimeBodyPart bodyPart2 = new MimeBodyPart();
bodyPart2.setContent("BBB", "text/plain");
messageMultipart.addBodyPart(bodyPart2);

Session session = Session.getDefaultInstance(System.getProperties(), null);
MimeMessage msg = new MimeMessage(session);
msg.setContent(messageMultipart);

System.out.println(msg.getContent());

ByteArrayOutputStream os = new ByteArrayOutputStream();
msg.writeTo(os);

ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
MimeMessage ms2 = new MimeMessage(session, is);

System.out.println(ms2.getContent());
}
}




The original message's content is a MimeMultipart and the read back message's content is String

Why? and how to make its type is read back correctly as a MimeMultipart    <<Less
About | Sitemap | Contact