msg.writeTo(System.out);
ByteArrayOutputStream out = new ByteArrayOutputStream(); msg.writeTo(out);  InputStream in = new ByteArrayInputStream(out.toByteArray());  MimeMessage newMessage = new MimeMessage(session, in);  assertEquals(((InternetAddress)newMessage.getSender()).getAddress(), "foo");  String[] headers = newMessage.getHeader("foo"); System.out.println("Get header returned " + headers); assertTrue(headers.length == 1); assertEquals(headers[0], "bar");   newMessage = new MimeMessage(msg);  assertEquals(((InternetAddress)newMessage.getSender()).getAddress(), "foo"); assertEquals(newMessage.getHeader("foo")[0], "bar");
    public void testWriteTo() throws MessagingException, IOException {        MimeMessage msg = new MimeMessage(session);        msg.setSender(new InternetAddress("foo"));        MimeMultipart mp = new MimeMultipart();        MimeBodyPart part1 = new MimeBodyPart();        part1.setHeader("foo", "bar");        part1.setContent("Hello World", "text/plain");        mp.addBodyPart(part1);        MimeBodyPart part2 = new MimeBodyPart();        part2.setContent("Hello Again", "text/plain");        mp.addBodyPart(part2);        msg.setContent(mp);        msg.writeTo(System.out);    }