EmailAddress Class
Provides properties and methods used to parse, examine and construct a single e-mail address.
Inheritance Hierarchy
SystemObject
  MailBee.MimeEmailAddress

Namespace: MailBee.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax
public class EmailAddress

The EmailAddress type exposes the following members.

Constructors
  NameDescription
Public methodEmailAddress
Initializes a new instance of the EmailAddress class
Public methodCode exampleEmailAddress(String)
Initializes a new instance of the EmailAddress object with the specified e-mail address.
Public methodCode exampleEmailAddress(String, String)
Initializes a new instance of the EmailAddress object from the specified e-mail address and display name.
Public methodCode exampleEmailAddress(String, String, String)
Initializes a new instance of the EmailAddress object from the specified e-mail address parts.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodStatic memberEscapeIdnDomain
Converts domain part of e-mail address string into IDN format.
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodFromIdnAddress
Gets a new EmailAddress object which is a copy of the current object with the domain part converted from IDN format.
Public methodCode exampleGetAccountName
Gets the account name of the e-mail address.
Public methodStatic memberCode exampleGetAccountNameFromEmail
Gets the account name of the specified e-mail address as a string.
Public methodCode exampleGetDomain
Gets the domain name of the e-mail address.
Public methodStatic memberCode exampleGetDomainFromEmail
Gets the domain name of the specified e-mail address as a string.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodStatic memberCode exampleParse
Parses an e-mail address string and returns EmailAddress object which represents the given e-mail addresses.
Public methodToIdnAddress
Gets a new EmailAddress object which is a copy of the current object with the domain part converted into IDN format.
Public methodCode exampleToString
Returns the e-mail address as a string.
(Overrides ObjectToString.)
Public methodStatic memberUnescapeIdnDomain
Converts domain part of e-mail address string from IDN format into Unicode.
Top
Operators
Properties
  NameDescription
Public propertyCode exampleAsString
Gets or sets the full e-mail address (with optional remarks and display name) as a string.
Public propertyCode exampleDisplayName
Gets or sets the name which is displayed with the e-mail address.
Public propertyCode exampleEmail
Gets or sets the actual e-mail address as a string.
Public propertyCode exampleRemarks
Contains the additional information (remarks) about the e-mail address.
Top
Remarks

In the most cases, the developer does not need to directly create an EmailAddress object to specify e-mail addresses because the most methods and properties which deal with e-mail addresses also accept string inputs as e-mail address values.

EmailAddress class offers AsString property for this. For instance, to specify MailMessage.From as a string, set msg.From.AsString value (assuming msg is MailMessage instance).

Multiple e-mail addresses (such as the list of To, CC or BCC recipients) can be stored in EmailAddressCollection of EmailAddress objects.

If you need to deal with international e-mail addresses (IDN domains), use FromIdnAddress and ToIdnAddress methods to convert e-mail addresses between human-readable and SMTP-safe formats.

Examples
This sample loads a message from .EML file and displays e-mail address details for each recipient.
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.Mime;

// The actual code (put it into a method of your class)

// Load the message from file.
MailMessage msg = new MailMessage();
msg.LoadMessage(@"C:\Docs\TestMail.eml");

// For every recipient...
foreach (EmailAddress adr in msg.To)
{
    // Show full information about the recipient's e-mail address.
    Console.WriteLine("Recipient name: " + adr.DisplayName);
    Console.WriteLine("Recipient address: " + adr.Email);
    Console.WriteLine("Recipient info: " + adr.Remarks);
    Console.WriteLine("Account name: " + adr.GetAccountName());
    Console.WriteLine("Domain name: " + adr.GetDomain());
}
See Also