DNS MX Record Issue

Giganews Newsgroups
Subject: DNS MX Record Issue
Posted by:  Jesse (nospam@fake.com)
Date: Wed, 19 Oct 2005

I have been using the following function with Indy 9 to retrieve MX Server
names to send e-mails to.  It worked just fine.  I upgraded to Indy 10 to
solve a problem I was having with TidMessage, and now, this function always
returns "mail.msdlg.com".  mail.msdlg.com is our mail server.  What do I
need to change in this function to make it retrieve the correct mail server?
As an example, I usually send "e.root-servers.net" as the initial NSServer,
and a domain may be "hotmail.com". Under Indy 9, if I recall correctly, it
used to return something like mx3.hotmail.com, but now it returns
mail.msdlg.com.  This will not work as we require authentication, plus, I
don't want to use our e-mail server unless we have to.

function TMainFrm.GetMXServers(const cNSServer : String;const cDomain :
String) : TStringList;
Var
  cNextServer : String;
  i : Integer;
Begin
  Result := TStringList.Create;
  DNSResolver.Host := cNSServer;
  DNSResolver.Resolve(cDomain);
  cNextServer := '';
  for i := 0 to DNSResolver.QueryResult.Count-1 do
  begin
      if DNSResolver.QueryResult[i] is TNSRecord then
      Begin
        cNextServer := TNSRecord(DNSResolver.QueryResult[i]).HostName;
        Break;
      end;
      if DNSResolver.QueryResult[i] is TMXRecord then
      begin
        with TMXRecord(DNSResolver.QueryResult[i]) do
            Result.AddObject(ExchangeServer,TObject(Integer(Preference)));
      end;
  end;
  if (Result.Count = 0) and (cNextServer <> '') then
      Result := GetMXServers(cNextServer,cDomain)
  else
      Result.CustomSort(SortServers);
end;

Thanks,
Jesse

Replies