MX Records, also known as Mail Exchanger records, are specific DNS (Domain Name System) records that deal with Mail Servers. Every mail server, that is publicly available to accept email, needs a special DNS record called Mail Exchanger records. These records point to specific domain name addresses or IP addresses, that are meant to receive email. When you send an email to someone@microsoft.com, your mail server looks up the domain microsoft.com, and asks for the MX records (the addresses that accept email). The DNS servers will return the records. Each MX record has a priority and an address associated with it. Your mail server then connects up to the address with the highest priority (the lowest numerical number) and send an email to someone@microsoft.com. If the connection fails, your mail server should then attempt to connect to the next server. As an example, here are the associated MX records for the domain microsoft.com
microsoft.com MX preference = 10, mail exchanger =
maila.microsoft.com
microsoft.com MX preference = 10, mail exchanger = mailb.microsoft.com
microsoft.com MX preference = 10, mail exchanger = mailc.microsoft.com
In this example, all of Microsoft's mail servers are weighted equally (10), thus your mail server will make it's own determination which mail server it wants to connect to first.
Using aspNetMX to get MX Records
Here are two quick code snippets to determine the MX Records of a domain:
[C#]
using System;
using aspNetMX;
namespace csTest
{
class Class1
{
//create a class level
MXValidate mx = new MXValidate();
[STAThread]
static void Main(string[] args)
{
string domainName = "microsoft.com";
MXValidate mx = new MXValidate();
MXServers servers = mx.GetMXServers( domainName );
MXRecord[] records = servers.Records;
foreach( MXRecord record in records)
{
//MXRecord.ToString() is an overloaded method that returns Priority:MailExchanger
Console.WriteLine( record.ToString() );
}
Console.ReadLine();
}
}
}
[Visual Basic]
Imports aspNetMX
Module Module1
'create a class level
Private mx As New MXValidate()
Sub Main()
Dim domainName As String = "microsoft.com"
Dim mx As New MXValidate()
Dim servers As MXServers = mx.GetMXServers(domainName)
Dim records As MXRecord() = servers.Records
Dim record As MXRecord
For Each record In records
'MXRecord.ToString() is an overloaded method that returns Priority:MailExchanger
Console.WriteLine(record.ToString())
Next record
Console.ReadLine()
End Sub
End Module