setText() with text/html contentType
HI,
I'm trying to send an e-mail with a contentType of "text/html". I'm able use the addHeader() method to set the contentType successfully, but when I try and set the body of text, the setText() method defaults the contentType to "text/plain". How do you set the body of text for an e-mail message with a different contentType? (Another method, etc...)
Duke dollars guarenteed to a successfull answer.
Thanks,
ddwb
[455 byte] By [
ddwb] at [2007-9-26 4:04:38]

Yes. javax.mail.internet.MimePart.setText() will reset the MIME type to "text/plain"
I have done setting of HTML message body(including proper MIME type i.e. "text/html") this way...
theMessage.setDataHandler(new javax.activation.DataHandler(new HTMLDataSource("mail body")))
where theMessage is your message object and HTMLDataSource is our own class. Here is the code for it...
import java.io.*;
public class HTMLDataSource implements javax.activation.DataSource
{
private String body;
public HTMLDataSource(String body)
{
this.body = body;
}
public InputStream getInputStream() throws IOException
{
return new ByteArrayInputStream(body.getBytes());
}
public OutputStream getOutputStream() throws IOException
{
throw new IOException("not supported");
}
public String getContentType() {
return("text/html");
}
public String getName()
{
return("haha");
}
}