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!

HTML tags in email

843834Mar 1 2008 — edited Mar 3 2008
Hello,

I am trying to send html in email but instead of html I just get plain text.

I am trying to send this string
<html><body><p>Hello</p></body></html>
I have tried to set content of the email to "text/html" as well as to "text/html; charset=\"ISO-8859-1\"".

I am viewing this email in Outlook 2007

Here is the method which sends the email.
public void sendMail(String fromEmail, String toEmail, String subject, String messageBody)
throws MessagingException {
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setContent(messageBody.toString(), "text/html");
//    message.setContent(messageBody, "text/html; charset=\"ISO-8859-1\"");
message.setFrom(new InternetAddress(fromEmail));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(toEmail));
message.setSubject(subject);
message.setText(messageBody);
Transport.send(message);
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 31 2008
Added on Mar 1 2008
3 comments
174 views