VirtualFab Email address checker 1.0
This article was contributed by
Fabio
Violino.
Environment: VB6 SP4, NT4 SP5
OVERVIEW
This VB6 COM component provides realtime Email address checking. This
is useful when you want to avoid sending Emails to non-existent accounts.
For example, in an ASP page you can check if the user typed his Email address
correctly, avoiding storing a wrong information in your users database.
CONTENTS
-
HOW DOES IT WORK?
-
COMPONENT FEATURES
-
INSTALLATION
-
USAGE
-
SAMPLE CODE
-
COMPONENT DOCUMENTATION
-
CREDITS
-
DOWNLOADS
-
HISTORY
HOW DOES IT WORK?
Giving an Email address (e.g. someone@somewhere.com),
it executes the following steps:
-
Separates the Username (someone) from DomainName (somewhere.com);
-
Queries the configured DNS server if DomainName is valid (exists);
-
If DNS answers, it tries a SMTP (Simple Mail Transfer Protocol) session
with each MX (Mail Exchanger) in that domain, as resulted from DNS query,
until a session can be established;
-
Using SMTP, it verifies that Username exists on that domain, both using
the VRFY (verify) command, and a true mail handshake (HELO, MAIL FROM,
RCPT TO);
-
It then returns the result of its search, giving 4 possible results:
-
The domain doesn't exist. Negative answer
-
The domain exists, but it isn't possible to check username (see note 1).
Partially positive answer.
-
The domain exists, but the username doesn't exist. Negative answer
-
Both the domain and the user exist, fully positive answer
Note 1: If the domain exists, but the MX Mail Exchangers aren't in that
domain (typical situation with secondary domains handled by ISPs), it's
no use to check via SMTP since those machines are instructed to accept
all mails for subdomains, and don't check username at all. So we stop and
take the partially positive answer.
COMPONENT FEATURES
This component
-
Finds DNS server as configured on the local machine. You must have an active
connection to the internet for this component to work properly
-
Sends DNS requests using the SimpleDNSResolver
component (see credits below)
-
Receives DNS answers via UDP
-
Establishes an SMTP session, via a standard Winsock.ocx TCP connection
-
Talks with remote mail server to find out information on user
-
Provides complete session log (DNS and SMTP) for debugging
-
Provides very small executable (it is an ActiveX DLL less than 50K in size)
-
It hasn't an user interface and must be used by any language that supports
ActiveX components (e.g. VBScript, ASP, VB, VC++, etc...)
-
Runs on Windows NT 4.0 SP5, Windows 2000 (not tested), Windows 95 (not
tested) and Windows 98 (not tested)
-
Compiles with VB 6.0 Service
Pack 4 (tested), but it can be compiled also in previous VB versions
(such as 5) that support Winsock.ocx
INSTALLATION
-
Download the package, unzip it into your preferred directory;
-
Copy the VfabEmailUtils.DLL into your SYSTEM directory (C:\WINNT\SYSTEM32
for Windows NT, or C:\WINDOWS\SYSTEM for Win9x)
-
Register the component into the registry:
-
REGSVR32 C:\WINNT\SYSTEM32\VfabEmailUtils.dll
-
IMPORTANT: to have this component working properly, you MUST install Emmanuel
KARTMANN's Simple DNS Resolver v1.0. Please click
here to read about how to install his package. See credits
below.
USAGE
To use this component:
-
Create an instance of the component;
-
Put properties:
-
EmailAddr
-
SmtpTimeOut
-
DNS server address (only under Win9x)
-
Call the CheckDomain method
-
Test the Result property: if it is not equal to vfabInvalidDomain (1) then
you can
-
Call the CheckUserName method;
-
Then test the Result property to get the final result:
-
vfabNotVerified = 0
-
vfabInvalidDomain = 1
-
vfabValidDomain = 2
-
vfabValidDomainInvalidAccount = 3
-
vfabValidDomainValidAccount = 4
SAMPLE CODE (VBScript
from an ASP page)
dim oVfab
set oVfab=CreateObject("VFabEmailUtils.EmailCheck")'Create
object instance
oVfab.EmailAddr = Request.Form("EMAIL")'Get
the address to check from ASP and assign it to object
oVfab.CheckDomain 'Check
if domain exists
If oVfab.Result <> 1 Then 'If
it exists, then try to check also UserName
oVfab.SmtpTimeOut = 10 'Give
the object 10 seconds to connect to remote SMTP server
oVfab.CheckUserName 'Tries
the SMTP session
End If
Response.Write "<br>" & oVfab.Log
(true) 'Displays session log in HTML format
Select Case oVfab.Result
Case 1
Response.Write "Domain name (<b>"
& oVfab.DomainName & "</b>) <b>INVALID</b>"
Case 2
Response.Write "Domain name: valid
- Cannot check account<br>"
Case 3
Response.Write "Domain name: valid
- Username (<b>" & oVfab.UserName & "</b>) <b>INVALID</b>"
Case 4
If oVfab.RealName <> "???" Then
Response.Write "Domain
Name: valid - Account verified - Real name: " & oVfab.realname &
"<br>"
Else
Response.Write "Domain
Name: valid - Account verified<br>"
End If
End Select
oVfab.Clear 'Clear
connections, logs, and status
COMPONENT DOCUMENTATION
METHODS:
Name |
Description |
CheckDomain() |
Checks the domain part of the Email address to see if it is a valid
(existent) domain |
CheckUserName() |
Checks the username via SMTP to see if it is a valid mail account
on that domain |
Clear() |
Clear connections, status and log after having completed the task |
PROPERTIES:
Name |
Type |
Read |
Write |
Description |
EmailAddr |
String |
Yes |
Yes |
Specify the Email address to check |
Result |
Integer |
Yes |
No |
Get the result of CheckDomain() and/or CheckUserName() |
SmtpTimeOut |
Integer |
Yes |
Yes |
Get/set the timeout in seconds to wait for an SMTP connection |
DnsServer |
String |
Yes |
No |
Set the DNS server IP address to use. Mandatory under Win9x, optional
in Windows NT |
RealName |
String |
Yes |
No |
Get the User's Real Name if provided by the SMTP server, after CheckUserName() |
DomainName |
String |
Yes |
No |
Get the domain part of EmailAddr |
UserName |
String |
Yes |
No |
Get the username part of EmailAddr |
Log(blnHTML) |
String |
Yes |
No |
Retrieves the session log, complete with all messages exchanged between
the client and the servers. If the optional parameter blnHTML is set to
true, it reformat the log with HTML line breaks for an easier reading |
SmtpServer |
String |
Yes |
No |
Get the complete list of MX servers for the domain |
CREDITS
This component strongly relies on SimpleDNSResolver
by Emmanuel KARTMANN .
Please refer to his page for details on the DNS architecture and on his
component.
DOWNLOADS
Download
source - 23 Kb
Download demo project - 2 Kb
HISTORY
Date Posted: August, 4th 2000