Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:52:01+00:00 2026-05-23T09:52:01+00:00

is there a simple way to look up if a domain has a MX

  • 0

is there a simple way to look up if a domain has a MX record or not using Delphi? I have a list of emails that I wish to verify work, I want to check each of the domains and see if a MX server even exists.

Thanks.

Edit: The email addresses I have are all from bounced email messages of error code: 5.4.0. But too many servers don’t follow any standards and 5.4.0 error code itself can mean too much. I don’t want to just remove all the email addresses found with that error code erroraneously, so I figure a better way is to first check if the domain or mx record don’t exist and remove those for sure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:52:01+00:00Added an answer on May 23, 2026 at 9:52 am

    It is actually good to have an e-mail checker. If nothing else you can clean you e-mail base and avoid sending over and over to non existing mails. Or you can use it as means of verifying user mails when they sign on to your application.

    Here is a part of the code in my mail checking class.

    procedure TMailValidator.ResolveEmailAddress(const Address: TEMailAddress; const DNSServer: string);
    var
      I: Integer;
      MXEmpty: Boolean;
      DomainName: string;
      DNSResolver: TIdDNSResolver;
    begin
      DNSResolver := TIdDNSResolver.Create(nil);
      try
        DomainName := StrAfter('@', string(Address));
        MXEmpty := True;
    
        DNSResolver.Host := DNSServer;
        {$IFNDEF IT_UseIndy9}
          DNSResolver.QueryType := [qtMx];
        {$ELSE}
          DNSResolver.QueryRecords := [qtMx];
        {$ENDIF}  // IT_UseIndy9
        try
          {$IFNDEF IT_UseIndy9}
            DNSResolver.WaitingTime := FDNSResolveTimeout;
          {$ELSE}
            DNSResolver.ReceiveTimeout := FDNSResolveTimeout;
          {$ENDIF}  // IT_UseIndy10
          DNSResolver.Resolve(DomainName);
    
          for I := 0 to DNSResolver.QueryResult.Count - 1 do
          begin
            if DNSResolver.QueryResult[I].RecType = qtMX then
            begin
              MXEmpty := False;
              CheckEmailAddress(Address, TMXRecord(DNSResolver.QueryResult[I]).ExchangeServer);
    
              // were we successfull
              if CheckSMTPExitErrorCode then
                Exit;
            end;
          end;
    
          // check for servers flag
          if FFoundMailServer then
          begin
            SendLogMessage(Format('Address "%s" is not valid on domain "%s"', [Address, DNSServer]));
            SetLastError(cUserErrorCodeBase + 5);
          end
          else
          begin
            if MXEmpty then
            begin
              SendLogMessage(Format('No valid mail(MX) server could be found for domain "%s"', [DomainName]));
              CheckEmailAddress(Address, DomainName);
            end
            else
            begin
              SendLogMessage(Format('Mail server did not respond on domain "%s"', [DomainName]));
              SetLastError(cUserErrorCodeBase + 3);
            end;
          end;
        except
          on E: Exception do
          begin
            SendLogMessage(Format('Address "%s" validation failed for domain "%s": %s', [Address,
                                                                                         DomainName,
                                                                                         E.Message]));
            SetLastError(cUserErrorCodeBase + 4, E.Message);
          end;
        end;
      finally
        DNSResolver.Free;
      end;
    end;
    
    
    procedure TMailValidator.CheckEmailAddress(const Address: TEMailAddress; const MailServer: string);
    var
      SMTP: TIdSMTP;
    begin
      SendLogMessage(Format('Validating address "%s" on server "%s"', [Address, MailServer]));
    
      if (FCheckStep = csAddress) or (FCheckStep = csDomain) then
      begin
        // finish if flags in [FLAG_CheckLocal, FLAG_CheckDomain]
        SendLogMessage(Format('Address "%s" successfuly validated.', [Address]));
        Exit;
      end;
    
      SMTP := TIdSMTP.Create(nil);
      try
        FCurrentStep := csMailBox;
        try
          SMTP.ReadTimeout := FSMTPReadTimeout;
          {$IFNDEF IT_UseIndy9}
            SMTP.AuthType := satNone;
          {$ELSE}
            SMTP.AuthenticationType := atNone;
          {$ENDIF}  // IT_UseIndy9
          SMTP.Host := MailServer;
          SMTP.Port := 25;
    
          SMTP.Connect;
          try
            FFoundMailServer := True;
    
            try
              SMTP.SendCmd('Helo ' + FQueryingServer, 250 );
              SMTP.SendCmd('Rset');
              SMTP.SendCmd('Mail from:<' + string(Address) + '>', 250);
              SMTP.SendCmd('RCPT to:<' + string(Address) + '>', [250, 251] );
    
              SendLogMessage(Format('Address "%s" successfuly validated on server "%s".', [FEMailAddress,
                                                                                           MailServer]));
            except
              on E: Exception do
              begin
                SendLogMessage(Format('Address "%s" validation failed on server "%s": %s', [Address,
                                                                                            MailServer,
                                                                                            E.Message]));
                SetLastError(SMTP.LastCmdResult.NumericCode, E.Message);
                Exit;
              end;
            end
          finally
            SMTP.Disconnect;
          end;
        except
          // handle all other exceptions
          on E: Exception do
          begin
            SendLogMessage(Format('CheckMail [%s] : Failure (Server) "%s" [%s]', [Address,
                                                                                  MailServer,
                                                                                  E.Message]));
            SetLastError(Max(cUserErrorCodeBase + 6, SMTP.LastCmdResult.NumericCode), E.Message);
          end;
        end;
      finally
        SMTP.Free;
      end;
    end;
    

    Basically you do it in three steps:

    1. Check the mail syntax.
    2. Check the domain and validate MX server
    3. Validate the user mailbox
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a simple way to get time time of day (17:30, 01:20...etc) that
I have a QString of JSON-encoded dictionaries. Is there a simple way to convert
I am using it like this: <%= Html.Pager((IPagination)Model) %> Is there are simple way
Is there any simple way to show only the files in my repository that
Is there any simple way to filter out a string in C using regular
Is there a simple way to insert the current time (like TIME: [2012-07-02 Mon
Is there a simple way to serialize a single-level structure as a string for
Is there a simple way, possibly with open-source command line tools in Linux, to
Is there a simple way in Symfony 1.4 to know whether a submitted form
Is there a simple way to move an element inside its own parent? Like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.