Reputation: 131
I am sending mail to outlook using java mail api. I am able to send plain text and html content mail but when I set content type to text/richtext but I receive mail in plain text only.
Can any body suggest how to send richtext mail? Here is what I tried:
// the parent or main part if you will
Multipart mainMultipart = new MimeMultipart("related");
// this will hold text and html and tells the client there are 2 versions of the message (html and text). presumably text
// being the alternative to html
Multipart htmlAndTextMultipart = new MimeMultipart("alternative");
// set html
MimeBodyPart htmlBodyPart = new MimeBodyPart();
htmlBodyPart.setContent("Hi", "text/richtext");
htmlAndTextMultipart.addBodyPart(htmlBodyPart);
MimeBodyPart htmlAndTextBodyPart = new MimeBodyPart();
htmlAndTextBodyPart.setContent(htmlAndTextMultipart);
mainMultipart.addBodyPart(htmlAndTextBodyPart);
message.setContent(mainMultipart);
Upvotes: 1
Views: 1321
Reputation: 383
Possibly are you getting confused between text/richtext and text/rtf
These are 2 different formats and is not related to HTML.
Upvotes: 1
Reputation: 13858
First - try adding richtext as content, not plaintext:
{\rtf1\ansi\deff0 {\fonttbl {\f0 Courier;}}
{\colortbl;\red0\green0\blue0;\red255\green0\blue0;}
This line is the default color\line
\cf2
\tab This line is red and has a tab before it\line
\cf1
\page This line is the default color and the first line on page 2
}
In code it might look like
htmlBodyPart.setContent("{\\rtf1\\ansi\\deff0 {\\fonttbl {\\f0 Courier;}}\r\n" +
"{\\colortbl;\\red0\\green0\\blue0;\\red255\\green0\\blue0;}\r\n" +
"This line is the default color\\line\r\n" +
"\\cf2\r\n" +
"\\tab This line is red and has a tab before it\\line\r\n" +
"\\cf1\r\n" +
"\\page This line is the default color and the first line on page 2\r\n" +
"}", "text/richtext");
Then you might want to think about actually providing an alternative text - so you could have two different versions.
Last it helps a lot to use an email client that allows you to look at the MIME source of the received message - like Mozilla Thunderbird does.
Upvotes: 1