Class MailAddressCollectionExtensions
- Namespace
- Wolfgang.Extensions.Mail
- Assembly
- Wolfgang.Extensions.Mail.dll
A collection of extension methods for the MailAddressCollection class.
public static class MailAddressCollectionExtensions
- Inheritance
-
MailAddressCollectionExtensions
- Inherited Members
Methods
AddRange(MailAddressCollection, IEnumerable<MailAddress>)
Adds a range of email addresses to the MailAddressCollection.
public static void AddRange(this MailAddressCollection source, IEnumerable<MailAddress> addresses)
Parameters
sourceMailAddressCollectionThe MailAddressCollection to add to
addressesIEnumerable<MailAddress>The list of MailAddress to add to the source
Exceptions
- ArgumentNullException
source is null
- ArgumentNullException
addresses is null
AddRange(MailAddressCollection, IEnumerable<string>)
Adds a range of email addresses to the MailAddressCollection.
public static void AddRange(this MailAddressCollection source, IEnumerable<string> addresses)
Parameters
sourceMailAddressCollectionThe MailAddressCollection to add to
addressesIEnumerable<string>The list of email addresses to convert to MailAddress and add to the source
Exceptions
- ArgumentNullException
source is null
- ArgumentNullException
addresses is null
AddRange(MailAddressCollection, params MailAddress[])
Adds a range of email addresses to the MailAddressCollection.
public static void AddRange(this MailAddressCollection source, params MailAddress[] addresses)
Parameters
sourceMailAddressCollectionThe MailAddressCollection to add to
addressesMailAddress[]The list of MailAddress to add to the source
Exceptions
- ArgumentNullException
source is null
- ArgumentNullException
addresses is null
AddRange(MailAddressCollection, params string[])
Adds a range of email addresses to the MailAddressCollection.
public static void AddRange(this MailAddressCollection source, params string[] addresses)
Parameters
sourceMailAddressCollectionThe MailAddressCollection to add to
addressesstring[]The list of email addresses to convert to MailAddress and add to the source
Exceptions
- ArgumentNullException
source is null
- ArgumentNullException
addresses is null
FormatMailAddress(MailAddress)
Returns a formatted RFC 5322 string representation of a single MailAddress.
public static string FormatMailAddress(this MailAddress address)
Parameters
addressMailAddressThe MailAddress to format.
Returns
- string
A formatted string such as
"Display Name" <email@example.com>.
Exceptions
- ArgumentNullException
addressis null.
ToFormattedString(MailAddressCollection, string)
Returns a formatted string representation of all addresses in the MailAddressCollection, using RFC 5322 display name quoting.
public static string ToFormattedString(this MailAddressCollection source, string separator = "; ")
Parameters
sourceMailAddressCollectionThe MailAddressCollection to format.
separatorstringThe separator between addresses. Defaults to
"; ".
Returns
- string
A formatted string of all addresses.
Examples
using var message = new MailMessage();
message.To.Add(new MailAddress("alice@example.com", "Alice Smith"));
message.To.Add(new MailAddress("bob@example.com"));
string formatted = message.To.ToFormattedString();
// "Alice Smith" <alice@example.com>; bob@example.com
Exceptions
- ArgumentNullException
sourceis null.