Dart.PowerTCP.EmailValidation Namespace > Validator Class > BeginValidate Method : BeginValidate(IList,Object) Method |
Validates email addresses in a non-blocking fashion.
[Visual Basic]
Overloads Public Function BeginValidate( _
ByVal emailAddresses As IList, _
ByVal state As Object _
) As IAsyncResult
[C#]
public IAsyncResult BeginValidate(
IList emailAddresses,
object state
);
[C++]
public: IAsyncResult* BeginValidate(
IList* emailAddresses,
Object* state
)
[C++/CLI]
public:
IAsyncResult^ BeginValidate(
IList^ emailAddresses,
Object^ state
)
Exception | Description |
---|---|
InvalidOperationException | BeginXXX method used without providing an EndXXX event handler. |
Use this overload when validating a list of email addresses. This overload has advantages over the single address overload. First, it makes use of TestAccount when this property is set. Second, it persists connections to mail servers hosting multiple addresses in the list.
The EndValidate event will fire when BeginValidate has completed.
The following example demonstrates the non-blocking validation of an email address list.
[Visual Basic]
Private Sub doValidation()
'Add "Imports Dart.PowerTCP.EmailValidation" at the top
'Add "Imports System.Collections.Specialized" at the top
'Add "Imports System.IO" at the top
'Validation settings
Validator1.ValidationLevel = ValidationLevel.SmtpRecipient 'final level
Validator1.BlackList = getList(Application.StartupPath + "\blacklist.txt")
Validator1.WhiteList = getList(Application.StartupPath + "\whitelist.txt")
Validator1.DomainCacheTimeout = 300 '300 second (5 minute) domain cache
Validator1.Smtp.TestAccount = "qwerty1298mnbvc" 'skip known "false positives"
'DNS settings
Validator1.Dns.RotateServers = False 'always start with first server
Validator1.Dns.Retries = 2 'try up to 3 times
Validator1.Dns.Timeout = 5000 '5 seconds
'SMTP settings
Validator1.Smtp.MailFrom = "myAccount@myDomain.com" 'required
Validator1.Smtp.ConnectTimeout = 40000 '40 seconds
Validator1.Smtp.ReceiveTimeout = 40000 '40 seconds
'Validate. EndValidate event will fire with result
Validator1.BeginValidate(getList(Application.StartupPath + "\myList.txt"), Nothing)
End Sub
Private Sub Validator1_EndValidate(ByVal sender As Object, ByVal e As ValidateEventArgs)_
Handles Validator1.EndValidate
'Examine the results
Dim results(e.Result.Length - 1) As String
Dim i As Integer
For i = 0 To results.Length - 1
results(i) = "The validation of " + e.Result(i).EmailAddress + " proceeded to the "
results(i) += e.Result(i).Progress.ToString() + " level. "
If (e.Result(i).Exception Is Nothing) Then
results(i) += "The validation was successful."
Else
results(i) += "The following exception occurred: " + e.Result(0).Exception.ToString()
End If
Next
'Pass the result to a displaying function
display(results)
End Sub
Private Function getList(ByVal filename As String) As StringCollection
'Read a list from a file
Dim list As StringCollection = New StringCollection
Dim reader As StreamReader = New StreamReader(filename)
While (reader.Peek() <= 0)
list.Add(reader.ReadLine())
End While
reader.Close()
Return list
End Function
[C#]
private void doValidation()
{
//Add "using Dart.PowerTCP.EmailValidation;" at the top
//Add "using System.Collections.Specialized;" at the top
//Add "using System.IO;" at the top
//Validation settings
validator1.ValidationLevel = ValidationLevel.SmtpRecipient; //final level
validator1.BlackList = getList(Application.StartupPath + "\\blacklist.txt");
validator1.WhiteList = getList(Application.StartupPath + "\\whitelist.txt");
validator1.DomainCacheTimeout = 300; '300 second (5 minute) domain cache
validator1.Smtp.TestAccount = "qwerty1298mnbvc";
//skip known "false positives"
//DNS settings
validator1.Dns.RotateServers = false; //always start with first server
validator1.Dns.Retries = 2; //try up to 3 times
validator1.Dns.Timeout = 5000; //5 seconds
//SMTP settings
validator1.Smtp.MailFrom = "myAccount@myDomain.com"; //required
validator1.Smtp.ConnectTimeout = 40000; //40 seconds
validator1.Smtp.ReceiveTimeout = 40000; //40 seconds
//Validate. EndValidate event will fire with result
validator1.BeginValidate(getList(Application.StartupPath + "\\myList.txt"), null);
}
private void validator1_EndValidate(object
sender, ValidateEventArgs e)
{
//Examine the results
string[] results = new string[e.Result.Length];
for (int i=0;
i<results.Length; i++)
{
results[i] = "The validation of " + e.Result[i].EmailAddress
+ " proceeded to the ";
results[i] += e.Result[i].Progress.ToString() + " level. ";
results[i] += (e.Result[i].Exception == null)
? "The validation was successful."
: "The following exception occurred:
" + e.Result[i].Exception.ToString();
}
//Pass the results to a displaying function
display(results);
}
private StringCollection getList(string filename)
{
//Read a list from a file
StringCollection list = new StringCollection();
StreamReader reader = new StreamReader(filename);
while (reader.Peek() >= 0)
list.Add(reader.ReadLine());
reader.Close();
return list;
}
Platforms: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP, Windows Server 2003, Windows Vista
Validator Class | Validator Members | Overload List
Send comments on this topic.
Documentation version 1.0.3.0.
© 2008 Dart Communications. All rights reserved.