The following article will describe how to use aspNetMX from Visual Studio .NET
using C#. This brief tutorial assumes you have IIS installed locally on your
machine, and have downloaded and installed aspNetMX from www.aspNetMX.com.
To skip this article, and view to the entire source:
Click here for C#.
Click here for VB.NET.
Using Visual Studio .NET (VS.NET ) You will create a single webform
(subscribe.aspx) that allows users to subscribe to a website newsletter list.
Subscribe.aspx will use aspNetMX to validate the email addresses before the
addresses are entered into the database. The following exmaple uses C#.
However, the VB.NET example can be found at the link above.
Because complete mailbox validation is a time-intensive process, and if a valid
email address's mail server might be down (resulting in a valid email address
being rejected), it's recommended that the validation level for aspNetMX NEVER
exceed MXValidateLevel.MXRecords when used in a website or from ASP.NET. This
guarantees a reasonable level of validation, without irritating the user with
unnecessary time delays. Please note that if your DNS server is down, or a
connection to your DNS server fails, valid email addresses may be considered
1. Launch Visual Studio .NET
2. From the main menu, select the File | New | Project
3. The New Project dialog box appears. Under
Project Types, Select Visual C# Projects. Under
Templates, select ASP.NET Web Application. In the
Location textbox, enter http://localhost/aspNetMXTest
Setting the Reference to aspNetMX.
1. In the Solution Explorer, right-click the project name,
aspNetMXTest, and select the Add | Add Existing Item
2. The Add Existing Item dialog box appears.
Under Files of Type, select All Files(*.*).
Navigate to the aspNetMX install directory. Double-click the aspNetMX.dll.
The Add Existing Item dialog box closes, and the aspNetMX.dll
was imported to the root directory of your project.
3. In the Solution Explorer, right-click the
project name aspNetMXTest and select Add Reference.
The Add Reference dialog box appears. Click the Browse
button. The Select Component dialog box appears. Double-click
the aspNetMX.dll file. The Select Component dialog
box closes. Click OK. The Add Reference dialog box closes, and
a reference is set to aspNetMX
Create a Test Page.
Now that we have a reference set, let's create subscribe.aspx to use aspNetMX.
1. In the Solution Explorer, right-click the
project name aspNetMXTest, and select Add | Add Webform.
The Add New Item dialog box appears. In the Name
textbox, enter, subscribe.aspx.
2. Subscribe.aspx loads in the designer window. Select the View
| Html Source menu command. The html code of subscribe.aspx appears.
Between the opening and closing form tags add the following html
Please enter your email address to subscribe to our newsletter. <br> <asp:TextBox ID="txtEmailAddress" runat=server></asp:TextBox><input type="submit" value="Submit" />
<asp:Literal ID="litMsg" Runat="server"></asp:Literal>
This code will create a html text box, a submit button, and
a <asp:Literal> tag that we will use for writing out a friendly user
3. In the Solution Explorer, right-click subscribe.aspx,
and select View Code.
4. Add the following using statement to the top of the
5. To the Page_Load method, add the following code.
if (Page.IsPostBack) //check email address
//download a license key from http://www.advancedintellect.com/download.aspx
//get an instance of MXValidate from the HttpCache
MXValidate mx = new MXValidate();
//check to see if the email address is valid
string email = txtEmailAddress.Text;
MXValidateLevel level = mx.Validate(email, MXValidateLevel.MXRecords);
if (level == MXValidateLevel.MXRecords)
//save to the database
//write out a friendly message
litMsg.Text = "Thank you for subscribing";
litMsg.Text = "Please enter a valid email address.";
//probably dns server not available, record the email address anyway, and double check when dns
//server is back up
litMsg.Text = "Thank you for subscribing";
This code first checks to see if the page was posted. If
the page was posted, the email address is attempted to be validated at the
MXRecord level. If the validation succeeds, MXValidateLevel.MXRecords is
returned. If validation would have failed, a lesser level, say
MXValidateLevel.NotValid or MXValidateLevel.Syntax would have been
returned. If an exception occurs, it is probably due to not being able to
connect to the DNS Server. Record the email address anyway, so a
potential subscriber is not lost.
6. Add the following helper method to the page.
private void SaveEmailAddress( string EmailAddress )
//this function is a placeholder and //would be used to
save EmailAddress //to
SaveEmailAddresses( string EmailAddress ) is a place
holder function that accepts a valid email address and would save it to your
Testing The Page
Lets compile and test the page.
1. In the Solution Explorer, right-click subscribe.aspx
and select View in Browser.
2. Enter an email address to check for validation, and click Submit
That's all there is to using aspNetMX from Visual Studio .NET. In these few
simple steps you were able to create a project, set a reference to aspNetMX,
and validate an address. For more questions or comments, feel free to write
Complete Source Code Listing
The entire source listing can be found here.
Copyright - Contact: Webmaster
Last Updated: Thursday, December 07, 2017