public static void Main()
var html = @"<html><head><meta name=""Generator"" content=""Microsoft Exchange Server"">
<!-- converted from text -->
<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style></head>
<font size=""2""><span style=""font-size:11pt;""><div class=""PlainText""> <p>Hello world, how are you doing today?</p><p>This is a separate <b>paragraph</b></p></div></span></font>
var plainText = ConvertHtml(html);
Console.WriteLine(plainText);
public static string Convert(string path)
HtmlDocument doc = new HtmlDocument();
StringWriter sw = new StringWriter();
ConvertTo(doc.DocumentNode, sw);
public static string ConvertHtml(string html)
HtmlDocument doc = new HtmlDocument();
StringWriter sw = new StringWriter();
ConvertTo(doc.DocumentNode, sw);
public static void ConvertContentTo(HtmlNode node, TextWriter outText)
foreach(HtmlNode subnode in node.ChildNodes)
ConvertTo(subnode, outText);
public static void ConvertTo(HtmlNode node, TextWriter outText)
case HtmlNodeType.Comment:
case HtmlNodeType.Document:
ConvertContentTo(node, outText);
string parentName = node.ParentNode.Name;
if ((parentName == "script") || (parentName == "style"))
html = ((HtmlTextNode)node).Text;
if (HtmlNode.IsOverlappedClosingElement(html))
if (html.Trim().Length > 0)
outText.Write(HtmlEntity.DeEntitize(html));
case HtmlNodeType.Element:
ConvertContentTo(node, outText);