+1 vote
by (130 points)
edited

We are building a portal and want to display some of the mail items and let people read the latest mail. The issue is that some mail is just too big and formatted to show in a webportal so we would like a method of stripping out the formatting and getting to a text based mail version if possible.

Ideally we still have some caraige returns and things like that but no huge hardcoded or poorly coded mails

Ideas?

Applies to: Rebex Secure Mail

1 Answer

+1 vote
by (13.0k points)
edited

Many email clients send both Html and Text version of the body. Try showing MailMessage.BodyText instead on MailMessage.BodyHtml on your web page.

If auto conversion from Html to Text is needed I would prefer using some of ready-made libraries over writing my own. You have to handle things like:

  • parsing HTML entities
  • unclosed tags
  • malformed html
  • malicious scripts in spams

Some people recommend using a HtmlAgility Pack.

Following articles on StackOverflow.com might also help:

...