aspose file tools*
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
Author

Trying to send HTML email but coming through as text email

Thomas Lloyd
Greenhorn

Joined: Jul 09, 2009
Posts: 1
Hi,

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
Thanks

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));

msg.setSubject(subject);

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");

Transport.send(msg);

Also Tried

HtmlEmail email = new HtmlEmail();
email.setHostName(props.getProperty("mail.smtp.host"));
email.addTo(to);
email.setFrom(from);
email.setSubject(subject);
email.setHtmlMsg(body);
email.send();*/


Result:

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"http://www.gladiator.co.uk/?media=3Dqfuem"><img src=3D"http=
://localhost/GladQE/pages/gladiator/emails/GEQ004A/gc_home_pic_top_0806.jpg"=
width=3D"171" height=3D"112" border=3D"0"></a></td> </tr> <tr> =
<td><a href=3D"http://www.gladiator.co.uk/?media=3Dqfuem"><img src=3D"h=
ttp://localhost/GladQE/pages/gladiator/emails/GEQ004A/gc_home_pic_bot_0806.j=

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to send HTML email but coming through as text email