MailMill .NET Class Library

Mail.CreateEmailAddress Method 

Helper function that builds a full email address from a display name and an email address.

public static string CreateEmailAddress(
   string name,
   string email
);

Parameters

name
Display name part of the email address.
email
Email address, must be a valid RFC2821 address.

Return Value

The full email address built from name and email

Remarks

A full email address is similar to what is defined in the RFC2822 as mailbox, except that the display name part supports unicode characters. CreateEmailAddress allows you to create valid full email address, even if the display name contains special chars like spaces, ", \, <, >, etc. If the display name is empty or contains only spaces, the email parameter is returned.

Exceptions

Exception Type Condition
ArgumentNullException name is a null reference (Nothing in Visual Basic)
-or-
email is a null reference (Nothing in Visual Basic).
MailMillException email is an invalid email address.

Example

This sample shows how to use the CreateEmailAddress method.

string sFullEmailAddress = Mail.CreateEmailAddress("Sales Departement", "sales@emilltest.com");
Console.WriteLine(sFullEmailAddress);
/* This code produces the following output:

"Sales Department" <sales@emilltest.com>*/

See Also

Mail Class | MailMill Namespace