Recursive AI

Check if an email address needs SMTPUTF8 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.

An email address needs SMTPUTF8 when the part before @ contains non-ASCII characters.

Terminal
dotnet add package RecursiveAI.OneContact

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using RecursiveAI.OneContact;
string[] inputs = ["josé@example.com",
    "info@bücher.example"];
const EmailFacts utf8 =
    EmailFacts.InternationalizedLocalPart;
foreach (var input in inputs)
{
    var email = EmailAddress.Parse(input);
    Console.WriteLine(email.Flags.HasFlag(utf8));
}

Unzip the example, then dotnet run.

Only the part before @ decides the result. The ü in info@bücher.example is in the domain, which has an ASCII form: xn--bcher-kva.example.

Text
True
False

The full program

The download compares the two flags and prints the canonical spelling of each address. All inputs are inline; it doesn’t contact a mail server.

C#
using RecursiveAI.OneContact;
 
foreach (var input in new[] { "josé@example.com", "info@bücher.example", "not-an-address" })
{
    if (!EmailAddress.TryParse(input, out var email))
    {
        Console.WriteLine($"{input}: could not parse");
        continue;
    }
 
    bool needsUtf8 = email.Flags.HasFlag(EmailFacts.InternationalizedLocalPart);
    bool idn = email.Flags.HasFlag(EmailFacts.InternationalizedDomain);
    Console.WriteLine($"{input} -> {email.Canonical}");
    Console.WriteLine($"  SMTPUTF8 for address: {needsUtf8}; IDN: {idn}");
}

dotnet run prints:

Text
josé@example.com -> josé@example.com
  SMTPUTF8 for address: True; IDN: False
info@bücher.example -> info@xn--bcher-kva.example
  SMTPUTF8 for address: False; IDN: True
not-an-address: could not parse

Parse throws ContactParseException on input it can’t parse. The full program uses TryParse instead so it can report a bad input and continue.

Variations

Check a domain already written in ASCII. Append this to the full program. The xn-- label still sets the internationalized-domain flag, not the local-part flag.

C#
var encoded = EmailAddress.Parse("info@xn--bcher-kva.example");
Console.WriteLine(encoded.Flags.HasFlag(EmailFacts.InternationalizedDomain));
Console.WriteLine(encoded.Flags.HasFlag(EmailFacts.InternationalizedLocalPart));

Added output:

Text
True
False

Validate an email address · Extract email addresses from text


The short answer

Parse the mailbox with EmailAddress.Parse, then test EmailFacts.InternationalizedLocalPart in email.Flags. The local part is the mailbox name before @. If that part contains non-ASCII characters, the address requires SMTPUTF8. InternationalizedDomain is a separate flag and does not answer the same question.

What is SMTPUTF8?

SMTPUTF8 is an SMTP extension for transporting internationalized email addresses and message headers. A mail server advertises support in its reply to EHLO. A parser working on an address string can tell you that josé@example.com needs the extension, but it can’t tell you whether a particular server offers it, whether the mailbox exists, or whether a message will arrive.

The check concerns one address. An ASCII recipient doesn’t rule out SMTPUTF8 for a message as a whole: another envelope address or internationalized headers can still need it. Likewise, a Unicode display name isn’t the local part. OneContact parses the display name separately and leaves it out of Canonical; the local-part flag isn’t a test for raw UTF-8 anywhere in a header.

Does an internationalized domain in Punycode need SMTPUTF8?

Not by itself. For info@bücher.example, the local part info is ASCII. OneContact converts the domain to its ASCII A-label form, xn--bcher-kva.example, giving info@xn--bcher-kva.example as the canonical address. RFC 6531 §3.2 does not treat an internationalized domain in A-label form as internationalized for this transport restriction.

The email parser docs describe InternationalizedDomain as a record that the domain went through IDNA processing, whether the input used Unicode or an xn-- label. That’s why the variation still reports the flag on info@xn--bcher-kva.example. It doesn’t make the ASCII spelling need SMTPUTF8.

Punycode for a domain doesn’t change the mailbox name before @. OneContact keeps the local-part spelling in Canonical (apart from the parsing cleanup described in the canonical-form docs). Don’t strip the accent in josé to make the SMTPUTF8 check pass: jose is a different local part and may designate a different mailbox.

All onecontact recipes