Email Address validation using IP*Works .NET
By Ben Higgins
October 4, 2003
IP*Works is now available to ASP.NET developers in a fully-managed .NET component.
The component offers the same functionality as the classic ASP component but does
not require the component to be installed on the production server. All you need
to do to utilize IP*Works is to drop it into your /BIN folder in the root of your
web application.
IP*Works provides many useful features including network troubleshooting tools like the TraceRoute or Ping utilities. You can also sending emails with attachments using
the SMTP or FileMailer feature. IP*Works also provides a FTP and TFTP component
which is very useful to web developers with web host providers that do not allow
anonymous FTP access. For a complete list of all of the features, visit /N Software's
website at http://www.nsoftware.com
In this article, I will demonstrate email validation, one of the features IP*Works
.NET offers to ASP.NET developers. IP*Works has many advantages over the built-in
ASP.Net classes.
One limitation of the built-in ASP.Net class is that you can only
validate email addresses based on the A record of their domain name. When using
just the A Record, I found that an email address that did not have a web address
associated with the domain name would fail. IP*Works solves this problem by allowing
you to validate against the MX record directly, a more efficient way to deal with
this type of validation.
The code below retrieves the MX record for a domain name cached on a DNS server.
Start with the HTML to build a simple form to submit an email address:
<body>
<form id="Form1" method="post" runat="server">
Enter your email address:
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:Button id="button1" runat="server" Text="Submit"> </asp:Button>
<asp:Label id="lblvalid" runat="server"></asp:Label>
</form>
</body>
Now for the code which is written
in VB.NET:
(Short explanations of the code follows)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim MX As New nsoftware.IPWorks.Mx
MX.Timeout = "20"
MX.DNSServer = "ns3.orcsweb.com"
MX.Resolve(TextBox1.Text)
If MX.MailServer <> "" Then
lblvalid.Text = MX.MailServer
Else
lblvalid.Text = "Email Address is not Valid"
End If
End Sub
The IP*Works component was invoked by declaring MX as new nsoftware.IPWorks.Mx.
The timeout was set to 20 seconds and uses ORCS Web's DNS server "ns3.orcsweb.com".
(You can use any DNS server you want.)
You can jump right to resolving the email address without removing the email username
and the "@" symbol by using "MX.Resolve()".
To retrieve the mail record use "MX.MailServer"
This is all you need to validate an email address. How you handle results is up to you. More example code is available by downloading the IP*Works .NET component
from http://www.nsoftware.com/
~Ben
Ben Higgins is a member of the
ORCS Web, Inc.
Webteam
- a company that provides managed hosting solutions for clients who develop and deploy their applications on Microsoft Windows platforms. Services include shared hosting, dedicated hosting, and webfarm hosting, with specialty in .Net, SQL Server, and architecting highly scalable solutions.