使用INDY9控件
function GetMailServers(Dns : string): Boolean;
var
I : integer;
begin
FDNSResolver := TIdDNSResolver.Create(nil);
try
if not assigned(fmailServers) then
fMailServers := TStringList.Create;
fmailServers.clear;
Result := True;
with FDNSResolver do
begin
Host := DNS;
ReceiveTimeout := 6000;
QueryRecords := [qtMX];
QueryResult.Clear;
Active := True;
try
FRelayStatus := 5;
Resolve('123.com');
Active := False;
if QueryResult.Count > 0 then
begin
for i := 0 to QueryResult.Count - 1 do
begin
if QueryResult is TMxRecord then
fMailServers.Append(TMXRecord(QueryResult).ExchangeServer);
end;
Result := True;
end
else
Result := False;
except
on E: Exception do
Result := False;
end;
end;
finally
FreeAndNil(FDNSResolver);
end;
end;