Hi There,
We are reading email content from Java servlet program and for the content types text/plain and text/html it is working fine while getting the content from this code for content type as text/html "
Code
String html = (String) bodyPart.getContent();Code
result = (String) bodyPart.getContent();Now for the content type text/enriched wrote the below code to retrieve the content
"
Code
InputStream is = (InputStream) bodyPart.getContent();
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer);
result= writer.toString();Here after getting the content it is formatting as paragraph,means complete content coming as one string.
Can you please help me to get this in proper html format instead of paragraph.
Below is the code which we tried.
Java
private static String getTextFromBodyPart(BodyPart bodyPart) throws IOException, MessagingException {
String result = "";
if (bodyPart.isMimeType("text/plain")) {
//result = (String) bodyPart.getContent();
result = (String) bodyPart.getContent();
result=txtToHtml(result);
} else if (bodyPart.isMimeType("text/html")) {
String html = (String) bodyPart.getContent();
result = html;
}
else if (bodyPart.isMimeType("text/enriched")) {
InputStream is = (InputStream) bodyPart.getContent();
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer);
result= writer.toString();
}
Answers
Know the answer? Post it. Somebody with the same question will find it here.