This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes Trying to send HTML email but coming through as text email Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Trying to send HTML email but coming through as text email" Watch "Trying to send HTML email but coming through as text email" New topic

Trying to send HTML email but coming through as text email

Thomas Lloyd

Joined: Jul 09, 2009
Posts: 1

I am trying to send html emails from my application running on a geronimo server on windows and using eclipse for development.
When I run this code on the J2EE preview server it works but when i run it on Geronimo is doesnt.

Here is the code that sends the email where i have added comments shows other code i have tried.

Beneath the code the email that comes through to outlook 2000

Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
to, false));


StringBuffer sbuf = new StringBuffer(body);

msg.setContent(new String(sbuf.toString().getBytes(), "iso-8859-1"), "text/html; charset=\"iso-8859-1\"");
msg.setSentDate(new Date());
//msg.setHeader("Content-Transfer-Encoding", "7bit");


Also Tried

HtmlEmail email = new HtmlEmail();


MIME-Version: 1.0
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><=
meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DISO-8859-1"=
/><title>GEQ004A_quote_1207.html</title></head><body><%@ include view=3D"gl=
adiator_mirror_page_left" %><table width=3D"600" border=3D"0" cellspacing=3D=
"0" cellpadding=3D"0"> <tr> <td width=3D"200" height=3D"10" bgcolor=3D"#=
009933"></td> <td width=3D"350" bgcolor=3D"#009933"></td> <td width=3D=
"50" bgcolor=3D"#009933"></td> </tr> <tr> <td valign=3D"top"><table wid=
th=3D"200" border=3D"0" cellspacing=3D"0" cellpadding=3D"0"> <tr> =
<td><a href=3D""><img src=3D"http=
width=3D"171" height=3D"112" border=3D"0"></a></td> </tr> <tr> =
<td><a href=3D""><img src=3D"h=

I agree. Here's the link:
subject: Trying to send HTML email but coming through as text email
jQuery in Action, 3rd edition