How to parse a HTML Mail Body?

Hi,

I try to write an Agent to parse the content of a HTML Mail.

I write the following Code, but it dose not work :-?

session.setConvertMIME(false);

MIMEEntity mime = docMail.getMIMEEntity();

Stream stream = session.createStream();

mime.getContentAsText(stream);

stream.close();

String sBody=stream.readText();

if (sBody.indexOf(“some text”)>-1) {

//... my code goes here...

}

sBody=sBody.toLowerCase();

But the String sBody always is emty?

Any idea?

Thanks for help

Ralph Soika

Subject: how to parse a HTML Mail Body?

Hi Ralph,

you close the stream object, so its paylod is voided. Reposition the stream with stream.position=0 instead of closing it. That should help.

hth

:slight_smile: stw