Blocking Address Validation Code Example
The following example demonstrates validation of an email address using the PowerTCP Validator component. Progress is provided during the operation.
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(doValidation("yourAddress@gmail.com"));
}
private string doValidation(string emailAddress)
{
//Validate to the ultimate level.
validator1.ValidationLevel = ValidationLevel.SmtpRecipient;
//Raise the progress event for every validation step.
validator1.VerboseProgress = true;
//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 = "from@myDomain.com"; //required
validator1.Smtp.ConnectTimeout = 40000; //40 seconds
validator1.Smtp.ReceiveTimeout = 40000; //40 seconds
//Validate and return the result.
ValidationState result = validator1.Validate(emailAddress);
string description = "The validation of " + result.EmailAddress;
description += " proceeded to the "; + result.Progress.ToString() + " level. ";
description += (result.Exception == null)
? "The validation was successful."
: "The following exception occurred: " + result.Exception.ToString();
return description;
}
private void validator1_Progress(object sender, ProgressEventArgs e)
{
//Record validation progress to a log.
if (e.ValidationState.Exception == null)
textLog.AppendText(e.ValidationState.EmailAddress + " OK: " +
e.ValidationState.Progress.ToString() + Environment.NewLine);
else
textLog.AppendText(e.ValidationState.EmailAddress + " ERROR: " +
e.ValidationState.Exception.Message + Environment.NewLine);
}