Home | Demo | Contact Us | Download | Support | Purchase | Shopping Cart | Products


Product List
 
  "WOW - I'm impressed. I've dealt with email support (from other companies) before and I really didn't think (or expect) I would get a response today (or tomorrow for that matter. I know that you usually only hear from customers when they have something to complain about so I just wanted to give you a "High Five" on the speed of your reply. Thank you very much for the PROMPT service! It is very much appreciated. "
Helmut
Rod n Reel
 
More
Testimonies


aspNetEmail
Voted Number 1 ASP.NET Email Control
Voted Best Email Control


aspNetEmail
Voted Number 1 ASP.NET Email Control
Voted Best Email Control


aspNetTraceRoute
Voted Runner Up Networking Control
Runner Up - Networking Control



The box is not shipped.

aspNetMX is a
downloadable product.

Summary

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, go here.

Instructions
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.

Note:
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 invalid.

1. Launch Visual Studio .NET

2. From the main menu, select the File | New | Project command.

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.
There are two ways to set a reference in VS.NET . Because aspNetMX is installed in the GAC (Global Assembly Cache) you can set a reference to the GAC copy, or you can import the aspNetMX.dll to the project and set a reference to the imported copy. We will upload a copy, and set a reference to the imported copy. This method will promote XCOPY deployment. (A comment about licensing: Please be sure you are compliant with your licenses. Check http://www.aspNetMX.com/licen.aspx for more information.)

1. In the Solution Explorer, right-click the project name, aspNetMXTest, and select the Add | Add Existing Item command.

2. The Add Existing Item dialog box appears. Under Files of Type, select All Files(*.*). Navigate to the aspNetMX install directory. By default, this directory is C:\Program Files\AdvancedIntellect\aspNetMX. 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>
<input type=text id=txtEmailAddress runat=server>
<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 message.

3. In the Solution Explorer, right-click subscribe.aspx, and select View Code.

4. Add the following using statement to the top of the page.

	using aspNetMX;

 

5. Be sure the following two lines of code to wire up the TextBox and <asp:Literal> are available at the class level.

	protected System.Web.UI.WebControls.Literal litMsg;
	protected System.Web.UI.HtmlControls.HtmlInputText txtEmailAddress;

6. To the Page_Load method, add the following code.

 

	
if( Page.IsPostBack) //check email address
{
	//get an instance of MXValidate from the HttpCache
	MXValidate mx = GetMXObject();
	
	//check to see if the email address is valid
	string email = txtEmailAddress.Value;
	try
	{
		MXValidateLevel level = mx.Validate( email, 
MXValidateLevel.MXRecords ); if( level == MXValidateLevel.MXRecords ) { //save to the database SaveEmailAddress( email ); //write out a friendly message litMsg.Text ="Thank you for subscribing"; } else { litMsg.Text = "Please enter a valid email address."; } } catch { //probably dns server not available, record the email
//address anyway, and double check when dns //server is back up SaveEmailAddress( email ); 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.

 

7. Add the two following helper methods to the page.

		
private void SaveEmailAddress( string EmailAddress )
{
	//this function is a placeholder and 
//would be used to save EmailAddress //to your data store. } //check to see if the MX object is already stored in cache //if not create it. This will allow us to take
//advantage of MXValidate's built in MX Cache private MXValidate GetMXObject() { MXValidate mx = (MXValidate)Cache["MXValidateObject"]; if( mx == null ) { //create the mx object mx = new MXValidate(); //increase the internal MX cache to be 1 day mx.CacheMXTimeOut = TimeSpan.FromDays( 1.0 ); //add MXValidate to the HttpCache Cache["MXValidateObject"] = mx; } return mx; }

SaveEmailAddresses( string EmailAddress ) is a place holder function that accepts a valid email address and would save it to your data store.

GetMXObject() retrieves a HttpCache stored instance of aspNetMX. aspNetMX is stored in the cache, so that it is only created once during the lifetime of the ASP.NET application. By doing this, aspNetMX will keep an internal MX Cache of previously looked up MX Records, resulting in faster validation.

Testing The Page
Lets compile and test the page.

1. In the Solution Explorer, right-click the project name, aspNetMXTest, and select Build. The project will be compiled.

2. In the Solution Explorer, right-click subscribe.aspx and select View in Browser.

3. Enter an email address to check for validation, and click Submit.

Summary
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 support@aspNetMX.com

Complete Source Code Listing
The entire source listing can be found here.