Here are a few Tips and Tricks to Optimize aspNetMX

aspNetMX has been highly optimized for general email address validation. However, there are a few techniques you can utilize to increase it's performance for your specific application.

 

Be Polite

It is against the licensing agreement to use aspNetMX for any type of email harvesting, spam, or illegal purposes. Be polite to remote mail serves. Do not attempt to validate many addresses of a single domain at one time. Mail server administrators will recognize your IP address, and may send you some unkind emails, complain to your ISP, or worse, block you from sending any email to their domain.

 

Create an Application Level Instance of aspNetMX.MXValidate

aspNetMX has a high performance MX Cache built in. Every time a MX record is located, it is stored in the internal aspNetMX MX Cache for quicker lookup. By having an application level instance of MXValidate, aspNetMX will build and maintain its cache, resulting in faster email address validation.

[C#]

using System;
using aspNetMX;
namespace csTest
{
	class Class1
	{
		//create a class level 
		private static MXValidate mx = new MXValidate();
		
		[STAThread]
		static void Main(string[] args)
		{
			//do some work with mx
		
		}
	}
}

[Visual Basic]

Imports aspNetMX
Module Module1

    'create a class level 
    Private mx As New MXValidate()

    Sub Main()
        'do some work with mx
    End Sub

End Module


Increase the Internal CacheMXTimeout

By default the internal MXCache stores records for 15 minutes. Increase the CacheMXTimeout value for the expected lifetime of your application.  If your application will run for several days or weeks, as a web application might, do not set the CacheMXTimeout longer than a few days.

[C#]

MXValidate mx = new MXValidate();
mx.CacheMXTimeOut= TimeSpan.FromDays( 1.0 );
[Visual Basic]
Dim mx As New MXValidate()
mx.CacheMXTimeOut = TimeSpan.FromDays(1.0)

 

Set the DNS Server(s) Manually       

By default aspNetMX performs an intensive examination of the system it is running on to determine the primary DNS server used for MX Record lookups. To skip this examination, manually specify the DNS server or servers.

[C#]

MXValidate mx = new MXValidate();
mx.DnsServer = "143.236.1.14";
[Visual Basic]
Dim mx As New MXValidate()
mx.DnsServer = "143.236.1.14"

 

Specify DNS Server(s) by IP Addresses

Use IP Addresses when specifying DNS Servers, for example 192.168.1.2. Do NOT specify names such as ns1.yahoo.com. If names are specified, additional network traffic and DNS queries will be performed to convert names to IP addresses.

[C#]

MXValidate mx = new MXValidate();
mx.DnsServer = "143.236.1.14";

[Visual Basic]

Dim mx As New MXValidate()
mx.DnsServer = "143.236.1.14"

 

Change the SMTP Hello Command

When a connection is established to a SMTP server, aspNetMX obeys the RFCs by saying 'hello' (SMPTHello) and introducing itself. By default aspNetMX uses the hostname of the server it is running on, however, depending upon how your DNS is configured, the hostname of your server may be different than the DNS name of your server.  Some mail servers will detect this discrepancy and deny access to you. Check with your network administrator to determine the EXACT DNS name of your server and set aspNetMX.SMTPHello to that name. For example:

[C#]

MXValidate mx = new MXValidate();
mx.SMTPHello = "myserver.mydomain.com";

[Visual Basic]

Dim mx As New MXValidate()
mx.SMTPHello = "myserver.mydomain.com"

 

Change the SMTPFrom Command

Following in the footsteps of SMTPHello, is the SMTPFrom command. SMTPFrom needs to be a valid email address. By default SMTPFrom is set to 'Validate@aspNetMXValidate.com'. This is a fake address, and mail servers may recognize it, and upon recognizing it, deny access to their servers.  Change SMTPFrom to a valid email address from your domain. For example, if you domain name is 'mycompany.com', a valid email address may be postmaster@mycompany.com.

[C#]

MXValidate mx = new MXValidate();
mx.SMTPFrom = "postmaster@mydomain.com";

[Visual Basic]

Dim mx As New MXValidate()
mx.SMTPFrom = "postmaster@mydomain.com"

Only Validate to MXValidateLevel.MXRecords in ASP.NET Applications

If you are using aspNetMX to validate email addresses entered by users on a web form, it's recommended you only validate to a MAXIMUM of MXValidateLevel.MXRecords. It's not unusual for a MXValidateLevel.Mailbox level to take 60 seconds or longer, which can delay and irritate users. However, relatively speaking,  MXValidateLevel.MXRecords is exponentially faster.  Once emails have been entered into the database, then run a 2nd and 3rd pass against them for full MXValidateLevel.Mailbox validation.

[C#]

MXValidate mx = new MXValidate(); 
MXValidateLevel level = mx.Validate( txtEmailAddress.Text , MXValidateLevel.MXRecords );
if( level == MXValidateLevel.MXRecords )
{
	//valid address
}
else
{
	//not valid address
}

[Visual Basic]
Dim mx As New MXValidate()
Dim level As MXValidateLevel = mx.Validate(txtEmailAddress.Text, MXValidateLevel.MXRecords)
If level = MXValidateLevel.MXRecords Then
	'valid address
Else
	'not valid address
End If 

When Validating to the MXValidateLevel.MXRecords Level, populate the KnownDomains Property

There are a number of domains that are known to exist, and have a high frequency of being added to your email list.  Some of these domains include "hotmail.com;aol.com;yahoo.com;usa.net;bigfoot.com;earthlink.net;mindspring.com;ibm.net;msn.com;compuserve.com;
juno.com;geocities.com;excite.com;altavista.com;ibm.com;microsoft.com;netzero.net" *.  If you are validating to the MXValidateLevel.MXRecords, and the email address is found to be valid, AND found in one these domains, aspNetMX will return a successful validation, thus saving the time it would take to perform MX Record lookups.

[C#]

MXValidate mx = new MXValidate();
string domains = "hotmail.com;aol.com;yahoo.com;usa.net;bigfoot.com;earthlink.net";
mx.AddKnownDomains( domains );

[Visual Basic]
Dim mx As New MXValidate()
Dim domains As String = "hotmail.com;aol.com;yahoo.com;usa.net;bigfoot.com;earthlink.net"
mx.AddKnownDomains(domains)

Take Advantage of the BadEmailAddresses ArrayList

aspNetMX has a property called BadEmailAddresses. This is an ArrayList that holds known bad email addresses. For example, how many times have you seen the email address 'test@test.com' or 'a@a.com' or 'asdf@asdf.com' entered into your address list?  While all of these addresses are technical valid, they are probably not too useful to you or your list. aspNetMX provides the capability to add these addresses to a 'Bad Address' list, and ever time they are encountered, aspNetMX automatically fails them.

[C#]

MXValidate mx = new MXValidate();
string bad = "test@test.com;a@a.com;asdf@asdf.com";
mx.AddBadEmails( bad );

[Visual Basic]
Dim mx As New MXValidate()
Dim bad As String = "test@test.com;a@a.com;asdf@asdf.com"
mx.AddBadEmails(bad)

 

 

When Validating to the MXValidateLevel.Mailbox level, populate the MailboxDomains Property

There are a number of domains that always return positive mailbox verification. Microsoft's Exchange server is known to do this. To prevent email address harvesting, these  mail servers will always claim a mailbox for an email address exists, when in fact, that email address may not exist. Some of these domains include "aol.com;yahoo.com;bigfoot.com;msn.com;compuserve.com;altavista.com;microsoft.com;netzero.net"*. To prevent time-intensive network calls from happening on those domains, aspNetMX exposes an ArrayList property called MailboxDomains. By adding these domains to the MailboxDomains ArrayList, aspNetMX will automatically approve any emails in these domains, to prevent the time-intensive Mailbox validation routine.  Because these domains always return positive results, the only way to correctly verify an email address is invalid, is to send an email to addresses found at these domains, and monitor any bounce backs or NDRs (non-deliverable receipts).

[C#]

MXValidate mx = new MXValidate();
string mailboxdomains = "aol.com;yahoo.com;bigfoot.com;msn.com";
mx.AddMailboxDomains( mailboxdomains );

[Visual Basic]
Dim mx As New MXValidate()
Dim mailboxdomains As String = "aol.com;yahoo.com;bigfoot.com;msn.com"
mx.AddMailboxDomains(mailboxdomains)

 

Change the DnsServerTimout Property

Depending upon how close your server is to the DNS server, server responsiveness, and network connectivity, you may want to change the DnsServerTimeout property.  The DnsServerTimeout property is set in milliseconds, and has a default value of 30000 (30 seconds). If you have a fast responding DNS server you may want to decrease this value to as little as 2000 (2 seconds).

[C#]

MXValidate mx = new MXValidate();
mx.DnsTimeout = 2000;

[Visual Basic]
Dim mx As New MXValidate()
mx.DnsTimeout = 2000

 

 

 

 

 

* Special thanks to James Shaw from www.CoverYourAsp.com for this list.