What is a good way to check the existence of mail domains on the client side?

Asked 1 years ago, Updated 1 years ago, 137 views


To prevent typing errors and unauthorized registration when entering a new member registration email address


I want to implement the function to check if the domain entered by the user exists.
*If possible, I would like to check the presence on the client side in real time


Java, JavaScript


▼About PHP email address determination
How do I determine if a string is an email address in PHP?

▼Determination of mail server using MX records in Java
http://www.rgagnon.com/javadetails/java-0452.html


Could you tell me how to check the domain on the client side?
(I'm a beginner and I don't think I can add any feasibility...)
I would appreciate it if you could give me advice on how to compromise, such as storing mail domain names in batch processing and comparing them with the input mail domain!

javascript java sendmail

2022-09-30 19:42

2 Answers

Could you tell me how to check the domain on the client side?

I think it would be better to contact DNS to check the existence of the domain of the email address, but I don't think DNS queries can be done on the client side.I think it would be better to consider implementing functions on the server side and calling them from JS on the client side.

Also, checking the existence of a domain in the first place does not confirm the existence of an email address.In short, it is often impossible to make a decision until you send it, so it might be wise to consider measures such as preventing you from registering as a member if you enter the wrong email address.


2022-09-30 19:42

Since there is no definition of "Do you have a domain?" I have decided to query whois by interpreting it as an intention to verify that it is not a random domain. I will use the whois query service at https://www.whoisxmlapi.com/ in jsonp.See also

varbaseURL='https://www.whoisxmlapi.com/whoisserver/WhoisService?';

varcheckDomain=function(domain, callback){
  var callback=callback||function(){},
      callbackName='__checkDomain_jsonp_callback_'+Date.now();
  window [callbackName] = function(data){
    callback(null,data.WhoisRecord);
  };
  varjsonpElement= document.createElement('script');
  jsonpElement.src=baseURL+'outputFormat=json&domainName='
    + encodeURIC component (domain) + '&callback=' + callbackName;
  jsonpElement.onerror=function(err){
  	callback(err);
  };
  document.body.appendChild(jsonpElement);
};

// example
checkDomain('example.com', function(err,data){
  console.log(err,data);
  if(data.dataError){
  	// If you have this property, you probably can't find whois → Not available
  }
});
checkDomain('example-not-exists-not-available.com', function(err,data){
  console.log(err,data);
  if(data.dataError){
  	// If you have this property, you probably can't find whois → Not available
  }
});

As I noticed from the comments, it might be better to check DNS's MX record.If there is a service available for http requests, I think we can do the same, and as you can see in the comments, you may have a server-side program that accepts http requests yourself.


2022-09-30 19:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.