definition
examples
The following code example shows sending an email message using the smtpclient, mailaddress, and mailmessage classes.
remarks
The mailaddress class is used by the smtpclient and mailmessage classes to store address information for email messages.
An email address is made up of a username, a hostname, and optionally a display name. the display name can contain non-ascii characters if you encode them.
The email address class supports the following email address formats:
-
a simple address format of user@host. if no display name is set, this is the generated email address format.
a standard quoted display name format of “display name” <user@host>. if a display name is set, this is the generated format.
Angle brackets are added around the username and hostname, if they are not included. for example, “display name” user@host is changed to “display name” <user@host>.
quotes are added around the display name, if they are not included. for example, display name <user@host> is changed to “display name” <user@host>.
unicode characters are supported in the display name property.
a username with quotes. for example, “username”@host.
consecutive and trailing periods in usernames. for example, user…name..@host.
domain literals in parentheses. for example, <username@[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 items in a list of email addresses. as a result, a comma should not be used in unquoted display names in a list. The following email addresses would be allowed:
“john, doe” , “bob, smith”
The following email address would not be allowed:
john, doe , bob, smith
quotes can be embedded in a quoted string, but must be escaped. The following email addresses would be allowed:
“john “jr” doe” <user@host>
“”john \”jr\” doe” <user@host>”
The following email address would not be allowed:
“john “jr” doe” <user@host>
When the username is not quoted, all text between the start of the string (or comma) and the address is considered part of the display name, including comments. for example:
(no comments) display without quotes (no comments) name (no comments) <user@host>
Although the mailaddress class accepts an email address as valid, other mail servers may not accept the email address.
The email address class does not support the following email address formats:
-
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 deprecated username formats of “user”.”name”@host, user.”name”@host, or “user”.name@host.
constructors
initializes a new instance of the mailaddress class using the specified address.
initializes a new instance of the mailaddress class using the specified address and display name.
initializes a new instance of the mail address class using the specified address, display name, and encoding.
properties
gets the email address specified when this instance was created.
gets the display name made up of the display name and address information specified when this instance was created.
gets the host portion of the address specified when this instance was created.
gets the user information for the address specified when this instance was created.
methods
compares two email addresses.
returns a hash value for an email address.
gets the type of the current instance.
creates a shallow copy of the current object.
returns a string representation of this instance.
create a new email address. does not throw an exception if the object cannot be created.
create a new email address. does not throw an exception if the object cannot be created.
create a new email address. does not throw an exception if the object cannot be created.
applies to
-