> >Check out DnsQuery component, I think that's what you need.
> Can it be done and how ?

This is a very simple MX lookup I wrote a long time ago, it fills two 
arrays with a list of SMTP servers for the domain and their priority, 
you are supposed to try the lowest numbered preference server first, 
then in increasing number if refused. sysdelay can be replaced by 
Application.ProcessMessages and GetTickCount for create the two second 
delay. 

Angus

// DNS commons vars
  ServersTotal: integer = 0 ;
  ServersList: array [1..9] of string ;
  ServersPref: array [1..9] of integer ;
  DNSReqId: integer ;

function TMainForm.GetMXServerName (email: string): boolean ;
var
        count, retries: integer ;
    domain: string ;
begin
        result := true ;
        ServersTotal := 0 ;
        for count := 1 to High (ServersList) do ServersList [count] := '' ;

// get domain from email address
        count := pos ('@', email) ;
    if count = 0 then exit ;
        domain := copy (email, count + 1, 88) ;

// set DNS server address - should really get whatver windows is using
    DnsQuery.Addr := DNSServer.Text ;
        for retries := 1 to 4 do        // UDP may ignore request
    begin
        DNSReqId := DnsQuery.MXLookup (domain) ;
            for count := 1 to 40 do     // wait two seconds
        begin
                        if ServersTotal <> 0 then
            begin
                if ServersTotal < 10 then result := false ;
              exit ;   // completed
                        end ;
           sysDelay (50) ;
            end ;
    end ;
end;

procedure TMainForm.DnsQueryRequestDone(Sender: TObject; Error: Word);
var
    I      : Integer;
    nIndex : Integer;
begin
        ServersTotal := 0 ;
    if DNSReqId <> DnsQuery.ResponseID then
    begin
       Error := 9999 ;
    end ;
    if Error = 0 then
    begin
        for I := 0 to DnsQuery.ResponseANCount - 1 do
        begin
                nIndex := DnsQuery.AnswerTag [I];
            if (nIndex >= 0) and 
                (DnsQuery.AnswerType [I] = DnsQueryMX) then
            begin
                inc (ServersTotal) ;
                ServersPref [ServersTotal] :=
                        DnsQuery.MXPreference [nIndex] ;
                    ServersList [ServersTotal] :=
                         DnsQuery.MXExchange [nIndex] ;
            end;
        end ;
        end ;
        if ServersTotal = 0 then ServersTotal := 99 ;   // error
end;
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to