See Also: MailAddress Members
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 simple address format of user@host. If a MailAddress.DisplayName is not set, this is the mail address format generated.
A standard quoted display name format of "display name" <user@host>. If a MailAddress.DisplayName is set, this is the format generated.
Angle brackets are added around the MailAddress.User name, MailAddress.Host name for "display name" user@host if these are not included.
Quotes are added around the MailAddress.DisplayName for display name <user@host>, if these are not included.
Unicode characters are supported in the MailAddress.DisplayName. property.
A MailAddress.User name with quotes. For example, "user name"@host.
Consecutive and trailing dots in user names. For example, user...name..@host.
Bracketed domain literals. For example, <user@[my domain]>.
Comments. For example, (comment)"display name"(comment)<(comment)user(comment)@(comment)domain(comment)>(comment). Comments are removed before transmission.
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