---
title: "Parse an email address in C#"
url: https://recursiveai.org/onecontact/cookbook/parse-email-address-with-display-name/
description: "Parse an email address in C# and read the display name, local part, domain, and canonical address. The example handles both named and bare mailboxes."
version: "1.0.0"
---

# Parse an email address in C#

**OneContact** is a free, open-source contact data library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies, no network access.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneContact) · [GitHub](https://github.com/recursive-ai-oss/onecontact-csharp) · [Docs](https://recursiveai.org/onecontact/docs/) · [Download example (.zip)](https://recursiveai.org/onecontact/cookbook/parse-email-address-with-display-name/parse-email-address-with-display-name.zip)

`Parse` returns the display name apart from the address.

```shell
dotnet add package RecursiveAI.OneContact
```

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

```csharp
using RecursiveAI.OneContact;
var email = EmailAddress.Parse(
    "Jane Doe <Jane@EXAMPLE.COM>");
Console.WriteLine(email.DisplayName);
Console.WriteLine(email.LocalPart);
Console.WriteLine(email.Domain);
Console.WriteLine(email.Canonical);
```

Prints the name, local part, domain, and normalized address, in that order:

```text
Jane Doe
Jane
example.com
Jane@example.com
```

Unzip [the example](https://recursiveai.org/onecontact/cookbook/parse-email-address-with-display-name/parse-email-address-with-display-name.zip), then `dotnet run`.

## Full program

The program uses two inline strings: a quoted name that contains a comma, and an address with no name.

```csharp
using RecursiveAI.OneContact;

foreach (var text in new[]
{
    "\"Doe, Jane\" <Jane+news@EXAMPLE.COM>",
    "jane@example.com"
})
{
    var email = EmailAddress.Parse(text);
    Console.WriteLine($"Name: {email.DisplayName ?? "(none)"}");
    Console.WriteLine($"Local part: {email.LocalPart}");
    Console.WriteLine($"Domain: {email.Domain}");
    Console.WriteLine($"Address: {email.Canonical}");
}
```

`dotnet run` prints:

```text
Name: Doe, Jane
Local part: Jane+news
Domain: example.com
Address: Jane+news@example.com
Name: (none)
Local part: jane
Domain: example.com
Address: jane@example.com
```

`Parse` throws `ContactParseException` if it can’t read the input as one mailbox; `TryParse` returns `false` instead.

## Variations

Read a mailbox whose quoted local part itself contains an `@`:

```csharp
using RecursiveAI.OneContact;
var email = EmailAddress.Parse(
    "\"orders@west\"@example.com");
Console.WriteLine(email.LocalPart);
Console.WriteLine(email.Domain);
```

```text
"orders@west"
example.com
```

## Related recipes

- [Validate email address syntax in C#](https://recursiveai.org/onecontact/cookbook/validate-email-address/)
- [Normalize an email address domain in C#](https://recursiveai.org/onecontact/cookbook/canonicalize-email-domain/)
- [Extract email addresses from text in C#](https://recursiveai.org/onecontact/cookbook/extract-emails-from-text/)

---

## The short answer

Call `EmailAddress.Parse` on one mailbox string. `DisplayName` is the optional name, `LocalPart` and `Domain` hold the two parts of the address, and `Canonical` gives you the address without the display name. Use the canonical address for an address field and keep the name in a separate field, rather than trying to recover it later from the canonical value.

## How do I parse an email address in C#?

Pass the whole field value, including any quotes and angle brackets. In `Jane Doe <Jane@EXAMPLE.COM>`, the name is outside the brackets and the address is inside. When the field is just `jane@example.com`, `DisplayName` is `null`; the parser doesn’t guess a name from `jane`. The full program shows both forms and demonstrates that the comma in `"Doe, Jane"` belongs to the name. The quotes are syntax and are not part of the returned name.

This is a parser for one mailbox, not an email-message parser. If you start with a full message, first get the mailbox field value from your message reader. If the field contains an address list or a group, don’t pass the whole field to `EmailAddress.Parse` or split it at every comma. The [email grammar notes](https://recursiveai.org/onecontact/docs/email/) explain what the parser accepts and why a list isn’t one mailbox.

## How do I split an email address into its local part and domain?

Read `LocalPart` and `Domain` from the result. Splitting at the first `@` fails on the quoted local part in the variation, and splitting the whole input ignores the fact that a display name can be present. Parsing first finds the actual address boundary and keeps meaningful quotes on the local part. That’s different from quotes around a display name, which are removed.

The parser keeps the local part’s case and a suffix such as `+news`; the domain is lowercased. A domain with internationalized labels is stored in ASCII form in `Domain`, and `UnicodeDomain` gives the readable form. If you need the original field exactly as received, keep the input separately. `Canonical` gives you a normalized address, not a round-trip copy of the field: the display name and comments aren’t included. These transformations are described in the [canonical form notes](https://recursiveai.org/onecontact/docs/email/#canonical-form).
