---
title: "Convert an HTML email body to plain text in C#"
url: https://recursiveai.org/onemail/cookbook/convert-html-email-body-to-plain-text/
description: "Convert an HTML email body to plain text in C# with OneMail. Keep line breaks and list markers, or use the message’s stored text when it is available."
version: "1.0.1"
---

# Convert an HTML email body to plain text in C#

**OneMail** is a free, open-source email library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneMail) · [GitHub](https://github.com/recursive-ai-oss/onemail-csharp) · [Docs](https://recursiveai.org/onemail/docs/) · [Download example (.zip)](https://recursiveai.org/onemail/cookbook/convert-html-email-body-to-plain-text/convert-html-email-body-to-plain-text.zip)

This example converts an HTML receipt while keeping its line breaks and list items.

```shell
dotnet add package RecursiveAI.OneMail
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneMail.Bodies;
var html = "<p>Receipt #42<br>Paid</p>" +
    "<ul><li>Tea &amp; honey</li>" +
    "<li>Oats</li></ul><p>Total: $12.50</p>";
var text = HtmlToText.Convert(html).Text;
Console.WriteLine(text);
```

```text
Receipt #42
Paid

* Tea & honey
* Oats

Total: $12.50
```

Unzip [the example](https://recursiveai.org/onemail/cookbook/convert-html-email-body-to-plain-text/convert-html-email-body-to-plain-text.zip), then `dotnet run`.

Use `BodySelector.GetText(message)` for a parsed email, or `HtmlToText.Convert` when you already have an HTML string.

## The full program

The download builds and parses an email with only a `text/html` body. `BodySelector.GetText` returns the converted body in that case, or the stored plain-text body when there is one. The receipt and headers are all in the code; there is no input file.

```csharp
using RecursiveAI.OneMail;
using RecursiveAI.OneMail.Bodies;
using RecursiveAI.OneMail.Composition;

const string html = """
    <p>Receipt #42<br>Paid</p>
    <ul><li>Tea &amp; honey</li><li>Oats</li></ul>
    <p>Total: $12.50</p>
    """;
var outgoing = new OutgoingMessage
{
    From = "store@example.com",
    To = ["buyer@example.org"],
    Subject = "Receipt #42",
    Html = html
};
var message = Mail.Parse(outgoing.ToEntity().ToArray());
var body = BodySelector.GetText(message)
    ?? throw new InvalidOperationException("No text or HTML body.");
Console.WriteLine(body.ReadText());
```

```text
Receipt #42
Paid

* Tea & honey
* Oats

Total: $12.50
```

If the message has neither text nor HTML to convert, `BodySelector.GetText` returns `null`.

## Variations

If you want a link’s visible label without its destination, use `LinkStyle.TextOnly`:

```csharp
using RecursiveAI.OneMail.Bodies;
var html = """
    <a href="https://example.org/42">Receipt</a>
    """;
var options = new HtmlToTextOptions
    { Links = LinkStyle.TextOnly };
Console.WriteLine(HtmlToText.Convert(html, options).Text);
```

```text
Receipt
```

## Related recipes

[Parse an EML file](https://recursiveai.org/onemail/cookbook/parse-eml/) · [Render email as HTML](https://recursiveai.org/onemail/cookbook/render-email-as-html/)

---

## The short answer

For a decoded HTML string, use `HtmlToText.Convert(html).Text`. For a parsed email, use `BodySelector.GetText(message)` so you get the author’s plain-text version when there is one. The HTML conversion is a fallback, not a rewrite of the original email.

## How do I convert HTML email to plain text without losing formatting?

Keep the structure that plain text can express. `HtmlToText` turns a `<br>` into a line break, separates paragraphs with a blank line, gives unordered lists `*` markers, and numbers ordered lists. It decodes character references, so `Tea &amp; honey` becomes `Tea & honey`. Simply removing tags could leave the item names running together. The conversion does not reproduce visual styling such as colors or font sizes.

This is body conversion, not HTML sanitization. The converter reads the email’s HTML and returns a string for plain-text use; it does not produce replacement markup. If you put that string back into a web page, display it as text, not as HTML.

## How do I display HTML email as plain text?

Use `BodySelector.GetText` for a parsed message rather than converting its HTML unconditionally. Some messages carry both a `text/plain` part and a `text/html` part. Using the stored plain-text part preserves the author’s wording and line breaks. The download exercises the other case: when the author provides only HTML, OneMail derives the fallback from it. `ReadText()` reads the selected result as a string.

With a decoded HTML string as input, `HtmlToText.Convert` returns conversion issues alongside the text. Check `Issues` if a preview looks incomplete; for example, an unusually long body can reach the character limit and return partial text. See the [body conversion reference](https://recursiveai.org/onemail/docs/bodies/#html-to-text) for the relevant options and issue names.
