Query Records using the MailExchangeRecord  class.

The following example demonstrates querying Mail Exchange records using the static method called GetMailExchangeRecords().

[C#]

using System;
using aspNetDns;
using aspNetDns.Records;
namespace ConsoleApplication1
{
	class Class1
	{
		[STAThread]
		static void Main(string[] args)
		{

			string LookupRecord = "microsoft.com";
			MailExchangeRecord[] records = MailExchangeRecord.GetMailExchangeRecords( LookupRecord );

			if( records.Length > 0 )
			{
				for( int i=0;i<records.Length;i++)
				{

					Console.WriteLine( "Exchange: " + records[i].Exchange);
					Console.WriteLine( "Preference: " + records[i].Preference.ToString() );
				}

			}
			else
			{
				Console.WriteLine( "No MX records were found.");
			}


			Console.WriteLine( "done.");
			Console.ReadLine();
		}
	}
}






 

[VB.NET]

Imports aspNetDns
Imports aspNetDns.Records
Module Module1

    Sub Main(ByVal args() As String)

        Dim LookupRecord As String = "microsoft.com"
        Dim records As MailExchangeRecord() = MailExchangeRecord.GetMailExchangeRecords(LookupRecord)
        If records.Length > 0 Then
            Dim i As Integer
            For i = 0 To records.Length - 1
                Console.WriteLine("Exchange: " + records(i).Exchange)
                Console.WriteLine("Preference: " + records(i).Preference.ToString())
            Next i

        Else
            Console.WriteLine("No MX records were found.")
        End If

        Console.WriteLine("done.")
        Console.ReadLine()

    End Sub 'Main

End Module