You need to sign in to do that
Don't have an account?
Lee_Campbell
Converting HTML to Plain Text in Inbound Email
Hi folks,
Is there any way I can convert the body of an inbound email from html to Plain Text? I've set up a service to email directly into chatter, but html emails sent from my organisation into Chatter are all of over 1,000 characters in length (even if I send a blank email). So, I'm looking for a way to strip the body text from the emails and discard all the html "nonsense", rather than force users to send emails in Plain Text format, which they'll be disinclined to do.
Any help anyone can give would be massively appreciated.
Thanks,
Lee
I found a parsing method somewhere else on the forum. You asnwered my query without moving a muscle! Thanks!
All Answers
I found a parsing method somewhere else on the forum. You asnwered my query without moving a muscle! Thanks!
Where is the parsing method you found?
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm
But be aware:
The stripHtmlTags function does not recursively strip tags; therefore, tags may still exist in the returned string. Do not use the stripHtmlTags function to sanitize input for inclusion as a raw HTML page. The unescaped output is not considered safe to include in an HTML document. The function will be deprecated in a future release.
Adrian Larson suggests:
in stack exchange (https://salesforce.stackexchange.com/questions/92828/how-can-i-convert-my-htmlbody-to-plaintextbody-using-apex-regex).
You'll also need to escape the backslash with double backslashes: