JAVA-how to manually compose a MIME multipart message

Posted by Augusto Picciani on Stack Overflow See other posts from Stack Overflow or by Augusto Picciani
Published on 2011-11-27T01:44:19Z Indexed on 2011/11/27 1:50 UTC
Read the original article Hit count: 272

Filed under:
|
|
|

I need to compose manually a MIME multipart message. I don't need to use any library to doing it. I'm trying this without success:

out.println("From:myemail@mydomain");
out.flush();
out.println("To:myemail@mydomain");
out.flush();
out.println("Date:Thu, 25 Nov 2011 01:00:50 +0100");
out.flush();
out.println("Subject:manual test 269");
out.flush();
out.println("MIME-version:1.0");
out.flush();

out.print("Content-Type: multipart/mixed; boundary=\"1234567\"\n\n");



out.println("--1234567");
out.flush();

out.println("Content-Type: text/plain; charset:utf-8");
out.flush();
out.print("Content-Transfer-Encoding: 7bit\n\n");
out.flush();

out.print("test message\n\n");
out.flush(); 
out.println("--1234567");
out.flush();
out.println("Content-Type: text/html; charset:utf-8");
out.flush();
out.print("Content-Transfer-Encoding: 7bit\n\n");
out.flush();

out.print("<p><strong>test message in html</strong></p>\n\n");
out.flush(); 
out.println("--1234567--");
out.flush();
out.print("\r\n.\r\n");
out.flush();

Problem is that my mail client see the headers (from,subject,date,ecc.) but it doesn't see the message body. If i try without multipart it works fine. Maybe problem is in whitespaces character.

© Stack Overflow or respective owner

Related posts about java

Related posts about android