PowerTCP Mail for .NET
SplitByDomain Method
See Also  Example Send comments on this topic.
Dart.PowerTCP.Mail Namespace > MailAddresses Class : SplitByDomain Method




Splits this collection in a set of MailAddresses by their Domain.

Syntax

Visual Basic (Declaration) 
Public Function SplitByDomain() As MailAddresses()
Visual Basic (Usage)Copy Code
Dim instance As MailAddresses
Dim value() As MailAddresses
 
value = instance.SplitByDomain()
C# 
public MailAddresses[] SplitByDomain()
Managed Extensions for C++ 
public: MailAddresses*[]* SplitByDomain(); 
C++/CLI 
public:
array<MailAddresses^>^ SplitByDomain(); 

Return Value

An array of MailAddresses collections, each being one Domain.

Example

The following example demonstrates the functionality of the MailAddresses collection.
Visual BasicCopy Code
' Be sure to import the namespace by putting "Imports Dart.PowerTCP.Mail"
' at the top of your class.

' Create a MailAddresses collection
Dim ma As New MailAddresses()

' Add a single email address
ma.Add(New MailAddress("address1@test.com"))

' Add a comma delimited list of email addresses.
ma.Add("address2@test.com,address3@test.com")

' Add an otherwise-delimited list of email addresses.
ma.Add("address2@test.com&address3@test.com", "&")

' Remove an email address
ma.Remove("address1@test.com")

' Remove any duplicate email addresses
ma.RemoveDuplicates()

System.Diagnostics.Debug.WriteLine(ma.ToString())

' Output
' ------------------
' <address2@test.com>,<address3@test.com>

' Add some more email addresses
ma.Add("mail1@other.com,mail2@other.com")

' Split the addresses by domain
Dim marray() As MailAddresses = ma.SplitByDomain()

Dim m As MailAddresses
For Each m In marray
   System.Diagnostics.Debug.WriteLine(m.ToString())
Next

' Output
' -----------------
' <mail1@other.com>,<mail2@other.com>
' <address2@test.com>,<address3@test.com>
'
C#Copy Code
// Be sure to import the namespace by putting "using Dart.PowerTCP.Mail;"
// at the top of your class.

// Create a MailAddresses collection
MailAddresses ma = new MailAddresses();

// Add a single email address
ma.Add(new MailAddress("address1@test.com"));

// Add a comma delimited list of email addresses.
ma.Add("address2@test.com,address3@test.com");

// Add an otherwise-delimited list of email addresses.
ma.Add("address2@test.com&address3@test.com", "&");

// Remove an email address
ma.Remove("address1@test.com");

// Remove any duplicate email addresses
ma.RemoveDuplicates();

System.Diagnostics.Debug.WriteLine(ma.ToString());

// Output
// ------------------
// <address2@test.com>,<address3@test.com>

// Add some more email addresses
ma.Add("mail1@other.com,mail2@other.com");

// Split the addresses by domain
MailAddresses[] marray = ma.SplitByDomain();
foreach(MailAddresses m in marray)
   System.Diagnostics.Debug.WriteLine(m.ToString());

// Output
// -----------------
// <mail1@other.com>,<mail2@other.com>
// <address2@test.com>,<address3@test.com>
//

Remarks

This method provides an easy way to seperate addresses by domains. For example, if the following addresses were added to a MailAddresses collection:

user1@domain1
user2@domain1
user1@domain2
user2@domain2
user3@domain2
				

...and the MailAddresses.Split method were called, an array of two MailAddresses objects would be returned, the first containing two addresses, and the second containing three.

This method takes theta(nlog(n)) time, and includes a sorting operation.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.