SmtpUtf8AddressValidator Class

A validator for internationalized (SMTPUTF8) email addresses.

Definition

Namespace: MimeKit.Utils
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public static class SmtpUtf8AddressValidator
Inheritance
Object    SmtpUtf8AddressValidator

Remarks

Validates email addresses according to the rules defined in draft-ietf-mailmaint-smtputf8-syntax, which restricts the code points that may be used in an internationalized email address in order to prevent addresses that render identically to (or deceptively similar to) other addresses.

An address is valid if and only if:

  1. It matches the Mailbox syntax defined in rfc5321 as extended by rfc6531.
  2. No atom in the local-part and no label in the domain is an A-label (i.e. begins with xn--).
  3. Every code point is either U+0020 SPACE or is permitted by the PRECIS IdentifierClass defined in rfc8264, including the contextual rules for CONTEXTJ and CONTEXTO code points defined in rfc5892.
  4. The address is in Unicode Normalization Form C (NFC) as defined by Unicode Standard Annex #15.
  5. The code points belong to no more than one non-ASCII script, where code points in the Common and Inherited scripts do not count toward that limit. Han, Hiragana and Katakana count as a single script (as used in Japanese), as do Han and Hangul, and Han and Bopomofo.

The length limits defined in rfc5321 are only enforced when EnforceLengthLimits is specified.

This validator has two primary uses:

  • Validating addresses that will be used in their internationalized (UTF-8) form, such as the addresses in the MAIL FROM and RCPT TO commands of an SMTP transaction that uses the SMTPUTF8 extension, or addresses that are being created or registered. SMTPUTF8 addresses must use U-labels, so by default an IDN-encoded domain such as user@xn--gr-zia.example.com is rejected (even though it is the correct way to express an internationalized domain in a context that only supports ASCII).
  • Detecting addresses that may be an attempt to spoof another address, such as addresses that mix scripts or that contain invisible or otherwise problematic code points, so that an application can warn the user. For this purpose, use DecodeIdn so that IDN-encoded domains are decoded into the Unicode form that would be displayed to the user and then validated. Consider also using AsciiIsLatin, which detects ASCII letters mixed with look-alike letters from another script (such as Cyrillic).

Methods

IsValid(MailboxAddress) Check whether a mailbox address is a valid SMTPUTF8 address.
IsValid(String) Check whether an address is a valid SMTPUTF8 address.
IsValid(MailboxAddress, SmtpUtf8AddressValidationOptions) Check whether a mailbox address is a valid SMTPUTF8 address.
IsValid(String, SmtpUtf8AddressValidationOptions) Check whether an address is a valid SMTPUTF8 address.
TryValidate(MailboxAddress, SmtpUtf8AddressError) Validate a mailbox address as an SMTPUTF8 address.
TryValidate(String, SmtpUtf8AddressError) Validate an address as an SMTPUTF8 address.
TryValidate(MailboxAddress, SmtpUtf8AddressValidationOptions, SmtpUtf8AddressError) Validate a mailbox address as an SMTPUTF8 address.
TryValidate(String, SmtpUtf8AddressValidationOptions, SmtpUtf8AddressError) Validate an address as an SMTPUTF8 address.

See Also