Re: iddnsresolver demo/examples??

Giganews Newsgroups
Subject: Re: iddnsresolver demo/examples??
Posted by:  Martin James (mjames_falc…@dial.pipex.com)
Date: Sat, 1 Nov 2003

"Anthony" <antho…@n.o.s.p.a.m.caltec.co.uk> wrote in message
news:E9FF91E88E84E240antho…@n.o.s.p.a.m.caltec.co.uk...
> argh! help!?
>
> Is it just me or has the DNS resolver demo got major issues? like it wont
> compile. at all. infact the code in the demo doesnt appear to relate to
the
> actual IdDNSResolver object at all?! - Im not even sure the demo is
> finished?
>
> All I want is a simple example of how to use the iddnsresolver object (in
> indy 9) to get the mx records (priority and host) for a given domain. It
> should be simple right? but Iv wasted days on it so far!

I don't know about the demo problems, but TidDNSresolver works fine for
getting MX servers, doing basically as Remy showed in his example.  The only
problem is that about 1 in 30 DNS requests fail to an internet server.
Since DNS uses UDP, this is not unexpected.  I get round this by timeouts &
retries, (I may also have my timeout set too short!).

Rgds,
Martin

**extract direct from working code - example only **

    function attemptResolve:boolean;
    var mxServerIndex:integer;
    begin
      with myDNSresolver do
      begin
        try
          host:=inSendObject.DNSserver;
          postError('DNS server: '+inSendObject.DNSserver);
          postError('Calling resolver');
          Resolve(messDomain);
          postError('Resolver returns with '+intToStr(QueryResult.count)+
            ' records');
          prefMin:=65535;
          indexPrefMin:=0;
          postError('Scan for best preference');
          for mxServerIndex:=0 to QueryResult.Count-1 do
          begin

thisPref:=TmxRecord(QueryResult.items[mxServerIndex]).preference;
            if (thisPref<prefMin) then
            begin
              prefMin:=thisPref;
              indexPrefMin:=mxServerIndex;
            end;
          end;
          postError('wBest server is
'+TmxRecord(QueryResult.items[indexPrefMin]).exchangeServer);

mySmtp.host:=TmxRecord(QueryResult.items[indexPrefMin]).exchangeServer;
          postError('Domain '+messDomain+' resolved to: '+mySmtp.host);
          lastDomain:=messDomain;
          lastHost:=mySmtp.host;
          result:=true;
        except
          on e:exception do
          begin
            postError('Resolve attempt '+intToStr(resolveRetryCount)+
            ' failed: '+              inSendObject.localMailServer+
            ': '+e.message);
            lastDomain:='';
            lastHost:='';
            result:=false;
          end;
        end; //try
      end;  // with

Replies

None

In response to

iddnsresolver demo/examples?? posted by Anthony on Thu, 30 Oct 2003