Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

outlook doesn't show text part for multiPart email.

843830May 10 2004 — edited Oct 11 2006

Hello,

I am trying to send an email with text content and html attachment, and the html has images with it. I want both the text and html.

The code works when I send the email to yahoo. It does display both text and html attachment. But when I send the email to outlook, the text part is gone and it only display the html. Outlook does indicate the email has attachment. But I can only save the image not the html. And the outlook email header does indicate it contains a text part.

Anyone encounter the same problem? I really appreciate it if anyone can point out what I am doing wrong here.

thanks.



Here is my code:
//should default to mixed subtype
MimeMultipart multipart1 =new MimeMultipart();

BodyPart part=new MimeBodyPart();
part.setContent("this is email body text\n and a lot of content.","text/plain");
multipart1.addBodyPart(part);

MimeMultipart multipart = new MimeMultipart("related");
BodyPart messageBodyPart = new MimeBodyPart();
String htmlText = "<H1>Hello</H1>" +"<img src=\"cid:memememe\">";
messageBodyPart.setContent(htmlText, "text/html");
multipart.addBodyPart(messageBodyPart);

BodyPart messageBodyPart1 = new MimeBodyPart();
DataSource fds = new FileDataSource("image.jpg");
messageBodyPart1.setDataHandler(new DataHandler(fds));
messageBodyPart1.setHeader("Content-ID","<"+"memememe"+">");
multipart.addBodyPart(messageBodyPart1);

MimeBodyPart mbp = new MimeBodyPart();
mbp.setContent(multipart);
multipart1.addBodyPart(mbp);

message.setContent(multipart1);

Comments

843830
Added the email header for some more info:

Mime-Version: 1.0
Content-Type: multipart/related;
boundary="----=_Part_0_16805237.1084225995843"
X-OriginalArrivalTime: 10 May 2004 21:53:18.0257 (UTC) FILETIME=[34115210:01C436D9]

------=_Part_0_16805237.1084225995843
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

------=_Part_0_16805237.1084225995843
Content-Type: multipart/related;
boundary="----=_Part_1_16250176.1084225995893"

------=_Part_1_16250176.1084225995893
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

------=_Part_1_16250176.1084225995893
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: <memememe>


------=_Part_1_16250176.1084225995893--

------=_Part_0_16805237.1084225995843--
843830
I'm having the same problem. Below is what Outlook does when it's used to send a web page. Looks like it's nesting a multipart within a multipart, although I'm not certain.
/* begin mime from Outlook email */
Content-Type: multipart/related;
boundary="----=_NextPart_000_0007_01C491AA.0B9812C0"


------=_NextPart_000_0007_01C491AA.0B9812C0
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_0008_01C491AA.0B9812C0"


------=_NextPart_001_0008_01C491AA.0B9812C0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset="us-ascii"

// html follows....

/* end outlook mime example */


Have you solved this problem yet?
843830
I also have this problem and would really like to find a solution.

Anyone have any idea why Outlook ignores/doesn't see the plain text message and only displays the html part?

Or how about an alternative to JavaMail :)
Bill Shannon-Oracle
I don't understand. You want a message when the primary
body of the message is text/plain, and the message has an
attachment, with completely different content than the primary
part, and the content is of type text/html? But Outlook only
displays the attachment and ignores the main body? Sounds
like a bug in Outlook.

You should have

multipart/mixed
text/plain
text/html, Disposition = ATTACHMENT

If Outlook can't display that properly, you might try something like

multipart/mixed
multipart/alternative
text/plain
text/html (same content as text/plain)
text/html, Disposition = ATTACHMENT

If even that fails, use Outlook to create the kind of message you
want and then examine the structure of the message that Outlook
creates.
843830
Thanks bshannon. I was using "alternative" instead of "mixed'.

The text/plain portion of email messages now appear when Outlook is set to read mail in plain text format - along with an html attachment (that stupid little icon).

Is it possible to include the html but *not* as an attachment? I get mail all the time that 'has been converted to plain text' by Outlook but has no attachment. The html is there as I can see it by choosing to read the message in html.

Maybe something like:

multipart/mixed
text/plain
text/html

Thanks again!
Bill Shannon-Oracle
Thanks bshannon. I was using "alternative" instead of
"mixed'.
Well, duh! Outlook was doing exactly what you told it to do.
It was picking the best of the two alternatives you gave it.
Is it possible to include the html but *not* as an
attachment? I get mail all the time that 'has been
converted to plain text' by Outlook but has no
attachment. The html is there as I can see it by
choosing to read the message in html.
I don't understand what you want to do. How do you want such
a message to be displayed?

Note that, in general, you have limited ability to control how
different mailers choose to display messages.
1 - 6
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Nov 8 2006
Added on May 10 2004
6 comments
1,372 views