You need to sign in to do that
Don't have an account?
RickoT1031
RE: Stripping html from HTMLBody of an inbound e-mail
Hello,
I need to process e-mails coming from a sharepoint form which of course does not submit both html and plaintext formatting, so I need a way to strip the HTML from the email without loosing the cariage returns of the email itself. I have been looking thru the forums and the docs but i have not been able to figure it out
Any suggestions?
I am attaching the code for stripping HTML , it makes use of two classes viz Pattern and Matcher.
Please find enclose the sample code :-
string html = 'your html code';
//first replace all <BR> tags with \n to support new lines
string result = html.replaceAll('<br/>', '\n');
result = result.replaceAll('<br />', '\n');
//regular expression to match all HTML/XML tags
string HTML_TAG_PATTERN = '<.*?>';
// compile the pattern
pattern myPattern = pattern.compile(HTML_TAG_PATTERN);
// get your matcher instance
matcher myMatcher = myPattern.matcher(result);
//remove the tags
result = myMatcher.replaceAll('');
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
I am attaching the code for stripping HTML , it makes use of two classes viz Pattern and Matcher.
Please find enclose the sample code :-
string html = 'your html code';
//first replace all <BR> tags with \n to support new lines
string result = html.replaceAll('<br/>', '\n');
result = result.replaceAll('<br />', '\n');
//regular expression to match all HTML/XML tags
string HTML_TAG_PATTERN = '<.*?>';
// compile the pattern
pattern myPattern = pattern.compile(HTML_TAG_PATTERN);
// get your matcher instance
matcher myMatcher = myPattern.matcher(result);
//remove the tags
result = myMatcher.replaceAll('');
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Seems to have worked like a charm, thank you very much for your input!
Ispita Saha... You're awesome!
It works great for me too.
Thanks a lot.
Alex