Home > Uncategorized > Validating a single e-mail address Synchronously

Validating a single e-mail address Synchronously

The easiest way to Validate a single email address is using Validate method of the ComponentSoft Email Validator library. You need to pass the email address you want to validate to this method and result value will show you what validation level the provided email address has passed.

UltimateEmailValidator verifies emails at five different levels. These levels includes:

Syntax Validates email address syntax defined by EmailSyntaxPattern.
Lists Verify up to the black and white list check. The black list is checked first.
If an email-address exists in both black list and white list, the email is treated as a valid email.
MailExchangeRecords Verify up to the Mail Exchange record check, does a DNS request for a domain’s mail exchange records. Certain mail servers may not have MX records but still be valid.  All checks above this level will still be attempted even if the MX record check fails.
SmtpConnection Verify up to the SMTP connection check, checks to see if a domains mail exchange can be connected to.
If no mail exchange is found it will attempt to connect to the A record for the domain specified in the address.
Mailbox Verify up to an SMTP send attempt.  Once the server accepts or rejects the email address the send is cancelled and no message is actually sent.

The following steps will help you to validate a single e-mail address:

Validating a single e-mail address

  1. Add using directives to your code to create aliases for existing namespaces and avoid having to type the fully qualified type names. The code looks similar to the following:
    C# Copy Code
    using ComponentSoft.Net;
    VB.NET Copy Code
    Imports ComponentSoft.Net
  2. Create a new instance of the EmailValidator class.
    C# Copy Code
    // Create a new instance of the EmailValidator class.
    EmailValidator client = new EmailValidator();
    VB.NET Copy Code
    ‘ Create a new instance of the EmailValidator class.
    Dim client As New EmailValidator()
  3. Now pass the e-mail address you want to validate to the Validate method. The code looks similar to the following:
    C# Copy Code
    // Validate the email.
    ValidationLevel result = validator.Validate(info@componentsoft.net);
    // Show result.
    MessageBox.Show(string.Format(“Email address ‘{0}’ has been validated at level {1}”, info@componentsoft.net, result.ToString()));
    VB.NET Copy Code
    ‘ Validate the email.
    Dim result As ValidationLevel = validator.Validate(“info@componentsoft.net”)
    ‘ Show result.
    MessageBox.Show(String.Format(“Email address ‘{0}’ has been validated at level {1}”, “info@componentsoft.net”, result.ToString()))

Final example code

C# Copy Code
// Create a new instance of the EmailValidator class.
EmailValidator validator = new EmailValidator();
// Validate the email.
ValidationLevel result = validator.Validate(info@componentsoft.net);
// Show result.
MessageBox.Show(string.Format(“Email address ‘{0}’ has been validated at level {1}”, info@componentsoft.net, result.ToString()));
VB.NET Copy Code
‘ Create a new instance of the EmailValidator class.
Dim validator As New EmailValidator()
‘ Validate the email.
Dim result As ValidationLevel = validator.Validate(“info@componentsoft.net”)
‘ Show result.
MessageBox.Show(String.Format(“Email address ‘{0}’ has been validated at level {1}”, “info@componentsoft.net”, result.ToString()))

Advertisement
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.