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!

why does subject line change to =?UTF-8?Q or Subject: =?Cp1252?Q?Hello=A0W

843830May 13 2002 — edited Dec 17 2004
Having a bugger of a time sending HTML/text email with Javamail.

If I'm really lucky, the subject line (originally "Hello World" will change to
: =?Cp1252?Q?Hello=A0World?= or =?UTF-8?Q?Hello=C2=A0World?= )
I say "lucky" because in those cases, at least the mail body is readable.

In other cases, the subject line doesn't appear at all and I receive this crud:

<snip>

To: <me@mydomain.com>

>
Subject: =?UTF-8?Q?Hello=C2=A0World?=
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_1_3097912.1021278578507"

------=_Part_1_3097912.1021278578507
Content-Type: text/plain
Content-Transfer-Encoding: 8bit

------=_Part_1_3097912.1021278578507
Content-Type: text/html;
Content-Transfer-Encoding: base64

PEhUTUw+DQo8SEVBRD4NCjxNRVRBIGh0dHAtZXF1aXY9IkNvbnRlbnQtVHlwZSIgY29udGVudD0i
dGV4dC9odG1sOyBjaGFyc2V0PVVURi04Ij4NCjxUSVRMRT5Eb3RMb3ZlLmNvbSBWYWxlbnRpbmUn
cyAyMDAyIE5ld3NsZXR0ZXI8L1RJVExFPg0KPC9IRUFEPg0KPEJPRFkgYmdDb2xvcj0iI0ZGRkZG

</snip>


The sick thing is that I can end up with the 2 different results using the same
code (below), but sent to 2 different email addresses which reside on the
same server and the message is read using the same client.

Having scoured the Forum, I'm using code which others have found to work :

<quote>

Properties props = System.getProperties();
props.put("mail.smtp.host", smtpHost);
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(sender);
message.addRecipient(Message.RecipientType.TO, receiver);
message.setSubject(subject);
message.setHeader("Mime-Version" , "1.0" );
// *** text : ***
MimeBodyPart multitext = new MimeBodyPart();
multitext.setText(textMsg);
multitext.setHeader("Content-Type", "text/plain");
multitext.setHeader("Content-Transfer-Encoding", "8bit");
// *** html: ***
MimeBodyPart multipartHTML = new MimeBodyPart();
multipartHTML.setText(htmlMsg);
multipartHTML.setHeader("Content-Type","text/html");
multipartHTML.setHeader("Content-Transfer-Encoding", "base64");
Multipart multipart = new MimeMultipart("alternative");
multipart.addBodyPart(multitext);
multipart.addBodyPart(multipartHTML);
message.setSentDate(new Date());
message.setContent(multipart);
Transport.send(message);

</quote>

Somebody put me out of my misery please :-)


Cheers,

chas



Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 14 2005
Added on May 13 2002
3 comments
684 views