Validating e-mail address

This sample validates e-mail address. First time, the address is validated for syntax only, second time, the address is also validated for e-mail address domain existence.

ValidateEmailAddress is a key method of this sample.

Note 1: Testing for domain existence can take some time (up to a few seconds) if particular domain does not exist.

Note 2: Even if e-mail address syntax is correct and domain exists, this still doesn't guarantee that e-mail address is valid. The only 100%-accurate way to validate e-mail address is to send e-mail to this address, wait some time and then check whether bounced e-mail has returned from this address.

Visual Basic

Dim objMsg

' We manually create Message object here. In your code,
' you can also reuse any existing Message object, such
' as SMTP.Message
Set objMsg = CreateObject("MailBee.Message")

' Check email address for syntax only. Because
' "mailbox@non-existent-domain.com" email is
' syntactically correct, the method will return True
If objmsg.ValidateEmailAddress("mailbox@non-existent-domain.com") Then
  MsgBox "E-mail address syntax is correct"
Else
  MsgBox "Syntax check failed"
End If

' Check email address for syntax and for domain existence.
' If "non-existent-domain.com" host does not exist, the method
' will return False
If objmsg.ValidateEmailAddress("mailbox@non-existent-domain.com", 1) Then
  MsgBox "E-mail address is probably correct"
Else
  MsgBox "E-mail address is incorrect"
End If

ASP

<%
Dim objMsg

' We manually create Message object here. In your code,
' you can also reuse any existing Message object, such
' as SMTP.Message
Set objMsg = Server.CreateObject("MailBee.Message")

' Check email address for syntax only. Because
' "mailbox@non-existent-domain.com" email is
' syntactically correct, the method will return True
If objmsg.ValidateEmailAddress("mailbox@non-existent-domain.com") Then
  Response.Write "E-mail address syntax is correct 
"
Else
  Response.Write "Syntax check failed 
"
End If

' Check email address for syntax and for domain existence.
' If "non-existent-domain.com" host does not exist, the method
' will return False
If objmsg.ValidateEmailAddress("mailbox@non-existent-domain.com", 1) Then
  Response.Write "E-mail address is probably correct"
Else
  Response.Write "E-mail address is incorrect"
End If
%>

See Also:

ValidateEmailAddress Method