System.Net.Mail.MailAddress Class

Represents the address of an electronic mail sender or recipient.

See Also: MailAddress Members

Syntax

public class MailAddress

Remarks

The System.Net.Mail.MailAddress class is used by the System.Net.Mail.SmtpClient and System.Net.Mail.MailMessage classes to store address information for e-mail messages.

A mail address is composed of a MailAddress.User name, MailAddress.Host name and optionally, a MailAddress.DisplayName. The MailAddress.DisplayName can contain non-ASCII characters if you encode them.

The System.Net.Mail.MailAddress class supports the following mail address formats:

A comma is used to separate elements in a list of mail addresses. As a result, a comma should not be used in unquoted display names in a list. The following mail addresses would be allowed

"John, Doe" <user@host>, "Bob, Smith" <user2@host>

The following mail address would not be allowed:

John, Doe <user@host>, Bob, Smith <user2@host>

Quotes can be embedded in a quoted string, but they must be escaped. The following mail addresses would be allowed

"John \"Jr\" Doe" <user@host>

"\"John \\\"Jr\\\" Doe\" <user@host>"

The following mail address would not be allowed:

"John "Jr" Doe" <user@host>

When the username is note quoted, all text between the start of the string (or comma) and the address are considered part of the MailAddress.DisplayName, including comments.

-- Example: (non comment) unquoted display (non comment) name (non comment) <user@host>

Although the System.Net.Mail.MailAddress class accepts a mail address as valid, other mail servers may not accept the mail address.

The System.Net.Mail.MailAddress class does not support the following mail address formats:

Mixed quoted and unquoted display names. For example, display "name" <user@host>

Groups, as defined in RFC 2822 Section 3.4 published by the IETF.

The obsolete user name formats of "user"."name"@host, user."name"@host or "user".name@host

Requirements

Namespace: System.Net.Mail
Assembly: System (in System.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0